This topic contains 4 replies, has 3 voices, and was last updated by
April 13, 2019 at 9:55 pm #151506ParticipantPoints: 17Rank: Member
I am working on some code for creating a new VM disk, and I can pass a hard-coded value in the capacity like shown below:
$vm = Get-VM VM $vm | New-HardDisk -CapacityGB 100 -Persistence persistent
I tried passing the Capacity from another value in my script two different ways instead of manually coding the 100GB (for example 50GB), however that makes my code fail to create that drive.
"New-HardDisk : Cannot bind parameter 'CapacityGB' to the target. Exception setting "CapacityGB": "Invalid value passed for the SizeGB parameter." "
A little background: Predefined the value from another array variable ($dataload) that has server information, among those "new_server_drive_size_g" = 50
$dataload.new_server_drive_size_g (I know that the output of this is '50')
Attempted passing this instead of '100' for CapacityGB.
$SizeG = $dataload.new_server_drive_size_g
Then I attempted passing the $SizeG instead of the hard-coded "100" for the capacity.
Same error both times. Is there a better way to do this? What am I missing?
April 14, 2019 at 12:56 am #151535ParticipantPoints: 1,367Rank: Community Hero
I assume it is about VMWare cmdlet New-HardDisk, right? 😉
According to the documentation the parameter -CapacityGB expects a decimal. The following code snippet might explain the difference between string and decimal ...
$OneHundret = '100' $OneHundret.GetType() $OneHundret = [DECIMAL]'100' $OneHundret.GetType()
April 14, 2019 at 1:41 am #151539ParticipantPoints: 17Rank: Member
Yes, it did however if it is CapacityGB then 100 is ok, so by that thought I should be able to pass it 50 from my variable, right?
April 14, 2019 at 4:07 am #151548ParticipantPoints: 948Rank: Major Contributor
What is the actual code?
April 14, 2019 at 9:50 am #151565ParticipantPoints: 1,367Rank: Community Hero
You must be logged in to reply to this topic.