VM parameter in Capacity

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

Attempt 1:

$dataload.new_server_drive_size_g (I know that the output of this is ‘50’)

Attempted passing this instead of ‘100’ for CapacityGB.

Attempt 2:

$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?

I assume it is about VMWare cmdlet New-HardDisk, right? :wink:
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()

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?

What is the actual code?

Cool.

Yes - definitely. Why didn’t you already try it? Would it hurt or kill you or someone else if you just tried?