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?