VM parameter in Capacity

Welcome Forums General PowerShell Q&A VM parameter in Capacity

This topic contains 4 replies, has 3 voices, and was last updated by

 
Participant
4 days, 4 hours ago.

  • Author
    Posts
  • #151506

    Participant
    Points: 17
    Rank: 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

    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?

  • #151535

    Participant
    Points: 1,367
    Helping Hand
    Rank: 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()
    • #151539

      Participant
      Points: 17
      Rank: 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?

  • #151548
    js

    Participant
    Points: 948
    Helping Hand
    Rank: Major Contributor

    What is the actual code?

  • #151565

    Participant
    Points: 1,367
    Helping Hand
    Rank: Community Hero

    Yes, it did ...

    Cool.

    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?

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

You must be logged in to reply to this topic.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort