Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vhd: Failed to create vhdx with error "One or more arguments are invalid" #153

Open
kellymenzel opened this issue Aug 17, 2018 · 5 comments
Labels
documentation The issue is related to documentation only. good first issue The issue should be easier to fix and can be taken up by a beginner to learn to contribute on GitHub help wanted The issue is up for grabs for anyone in the community.

Comments

@kellymenzel
Copy link

kellymenzel commented Aug 17, 2018

Details of the scenario you tried and the problem that is occurring:
I'm trying to use xVHD to create a virtual hard drive on a Hyper-V server running in Windows Server 1709. I dot sourced the Sample_xVHD_NewVHD.ps1 example from this repository and compiled and ran it. But even with the simplest configuration, I receive an error.

The DSC configuration that is using the resource (as detailed as possible):

. .\Sample_xVHD_NewVHD.ps1
Sample_xVHD_NewVhd -Name "test" -Path "D:\" -MaximumSizeBytes 5000000 -Generation Vhdx
Start-DscConfiguration -Path '.\Sample_xVHD_NewVhd' -Verbose -Wait -Force 

Result:

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' =
SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' =
root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer CORP-VMHOST-01 with user sid
S-1-5-21-1659004503-963894560-1801674531-3634.
VERBOSE: [CORP-VMHOST-01]: LCM:  [ Start  Set      ]
VERBOSE: [CORP-VMHOST-01]: LCM:  [ Start  Resource ]  [[WindowsFeature]HyperV]
VERBOSE: [CORP-VMHOST-01]: LCM:  [ Start  Test     ]  [[WindowsFeature]HyperV]
VERBOSE: [CORP-VMHOST-01]:                            [[WindowsFeature]HyperV] The operation 'Get-WindowsFeature'
started: Hyper-V
VERBOSE: [CORP-VMHOST-01]:                            [[WindowsFeature]HyperV] The operation 'Get-WindowsFeature'
succeeded: Hyper-V
VERBOSE: [CORP-VMHOST-01]: LCM:  [ End    Test     ]  [[WindowsFeature]HyperV]  in 0.8440 seconds.
VERBOSE: [CORP-VMHOST-01]: LCM:  [ Skip   Set      ]  [[WindowsFeature]HyperV]
VERBOSE: [CORP-VMHOST-01]: LCM:  [ End    Resource ]  [[WindowsFeature]HyperV]
VERBOSE: [CORP-VMHOST-01]: LCM:  [ Start  Resource ]  [[WindowsFeature]HyperVPowerShell]
VERBOSE: [CORP-VMHOST-01]: LCM:  [ Start  Test     ]  [[WindowsFeature]HyperVPowerShell]
VERBOSE: [CORP-VMHOST-01]:                            [[WindowsFeature]HyperVPowerShell] The operation
'Get-WindowsFeature' started: Hyper-V-PowerShell
VERBOSE: [CORP-VMHOST-01]:                            [[WindowsFeature]HyperVPowerShell] The operation
'Get-WindowsFeature' succeeded: Hyper-V-PowerShell
VERBOSE: [CORP-VMHOST-01]: LCM:  [ End    Test     ]  [[WindowsFeature]HyperVPowerShell]  in 0.4690 seconds.
VERBOSE: [CORP-VMHOST-01]: LCM:  [ Skip   Set      ]  [[WindowsFeature]HyperVPowerShell]
VERBOSE: [CORP-VMHOST-01]: LCM:  [ End    Resource ]  [[WindowsFeature]HyperVPowerShell]
VERBOSE: [CORP-VMHOST-01]: LCM:  [ Start  Resource ]  [[xVHD]NewVhd]
VERBOSE: [CORP-VMHOST-01]: LCM:  [ Start  Test     ]  [[xVHD]NewVhd]
VERBOSE: [CORP-VMHOST-01]:                            [[xVHD]NewVhd] Vhd full name is test.Vhdx
VERBOSE: [CORP-VMHOST-01]:                            [[xVHD]NewVhd] Vhd full path is D:\test.Vhdx
VERBOSE: [CORP-VMHOST-01]:                            [[xVHD]NewVhd] Vhd D:\test.Vhdx is present:False and Ensure is
Present
VERBOSE: [CORP-VMHOST-01]: LCM:  [ End    Test     ]  [[xVHD]NewVhd]  in 0.4690 seconds.
VERBOSE: [CORP-VMHOST-01]: LCM:  [ Start  Set      ]  [[xVHD]NewVhd]
VERBOSE: [CORP-VMHOST-01]:                            [[xVHD]NewVhd] Vhd full name is test.Vhdx
VERBOSE: [CORP-VMHOST-01]:                            [[xVHD]NewVhd] Vhd full path is D:\test.Vhdx
VERBOSE: [CORP-VMHOST-01]:                            [[xVHD]NewVhd] Checking if D:\test.Vhdx is Present ...
VERBOSE: [CORP-VMHOST-01]:                            [[xVHD]NewVhd] D:\test.Vhdx is not Present
Failed to create the virtual hard disk.
The system failed to create 'D:\test.Vhdx'.
Failed to create the virtual hard disk.
The system failed to create 'D:\test.Vhdx': One or more arguments are invalid (0x80070057).
    + CategoryInfo          : InvalidArgument: (:) [], CimException
    + FullyQualifiedErrorId : InvalidParameter,Microsoft.Vhd.PowerShell.Cmdlets.NewVhd
    + PSComputerName        : localhost

VERBOSE: [CORP-VMHOST-01]:                            [[xVHD]NewVhd] D:\test.Vhdx is now Present
VERBOSE: [CORP-VMHOST-01]: LCM:  [ End    Set      ]  [[xVHD]NewVhd]  in 1.1870 seconds.
The PowerShell DSC resource '[xVHD]NewVhd' with SourceInfo '::48::9::xVhd' threw one or more non-terminating errors
while running the Set-TargetResource functionality. These errors are logged to the ETW channel called
Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : localhost

VERBOSE: [CORP-VMHOST-01]: LCM:  [ End    Set      ]
The SendConfigurationApply function did not succeed.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : localhost

VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 3.885 seconds

Version of the Operating System and PowerShell the DSC Target Node is running:
Windows Server 1709

Version of the DSC module you're using, or 'dev' if you're using current dev branch:
xHyper-V 3.12.0.0

PS>$PsVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.16299.551
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.551
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
@johlju
Copy link
Member

johlju commented Aug 17, 2018

The problem seems to be the $Type property

https://github.com/PowerShell/xHyper-V/blob/528678479e6f82f421e0622554ecc8719da211e6/DSCResources/MSFT_xVHD/MSFT_xVHD.psm1#L113-L116

It just adds Type = $true here.

https://github.com/PowerShell/xHyper-V/blob/528678479e6f82f421e0622554ecc8719da211e6/DSCResources/MSFT_xVHD/MSFT_xVHD.psm1#L206-L211

There are no parameter named Type on the cmdlet New-Vhd. Instead $Type should be evaluated to either -Differencing, -Dynamic or -Fixed.

@johlju johlju added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. good first issue The issue should be easier to fix and can be taken up by a beginner to learn to contribute on GitHub labels Aug 17, 2018
@johlju
Copy link
Member

johlju commented Aug 17, 2018

This was not caught in the tests because the cmdlet is overriden with no parameters. Instead there should be made a stub module file of the Hyper-V cmdlets. See example of creating a stub module file here Write-ModuleStubFile.ps1

https://github.com/PowerShell/xHyper-V/blob/528678479e6f82f421e0622554ecc8719da211e6/Tests/Unit/MSFT_xVHD.tests.ps1#L239-L242

@johlju johlju changed the title xVHD - Failed to create vhd. One or more arguments are invalid. Windows Server 1709 xVHD: Failed to create vhdx with error "One or more arguments are invalid" Aug 17, 2018
@johlju
Copy link
Member

johlju commented Aug 17, 2018

@kellymenzel Thank you for reporting this issue! Labeled is help wanted so that anyone in the community can run with this.

@kellymenzel
Copy link
Author

I delved into this and found that there really isn't a bug, but there is a very strange, possibly intentional behavior in the New-VHD cmdlet...

New-VHD -Path 'C:\Test.vhdx' -SizeBytes 5000000 -Dynamic

...I get the 'One or more arguments are invalid' error. However, if I type

New-VHD -Path 'C:\Test.vhdx' -SizeBytes 5242880 -Dynamic

The VHD file is created just fine. Note, the size is 5 * 1024 * 1024.

Splatting the switch is working just fine. Note, in the Params hash table, it's $Type, not Type which would evaluate to -Dynamic:$True

@johlju johlju removed the help wanted The issue is up for grabs for anyone in the community. label Aug 17, 2018
@johlju
Copy link
Member

johlju commented Aug 17, 2018

Ah I miss read the hash table. Thank you for sharing this. Let’s open this again and we could update the documentation for that parameter.

@johlju johlju reopened this Aug 17, 2018
@johlju johlju added help wanted The issue is up for grabs for anyone in the community. documentation The issue is related to documentation only. and removed bug The issue is a bug. labels Aug 17, 2018
@johlju johlju changed the title xVHD: Failed to create vhdx with error "One or more arguments are invalid" Vhd: Failed to create vhdx with error "One or more arguments are invalid" Jun 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation The issue is related to documentation only. good first issue The issue should be easier to fix and can be taken up by a beginner to learn to contribute on GitHub help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

No branches or pull requests

2 participants