PowerShell & Hyper-V (PoC)

Welcome Forums General PowerShell Q&A PowerShell & Hyper-V (PoC)

Viewing 5 reply threads
  • Author
    Posts
    • #270805
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Hi Guys,

      I’m currently working on a powershell script to build my PoC environment and using the following code to set memory for each of my VMs

      $MemoryAvailable = (Get-VMHostNumaNode).MemoryAvailable/4

      I’m splitting the total memory by 4 to get the number which in this case for 16GB computer is 4067. Then I’m rounding it off to 4GB as per next command

      $maxRAM = ([math]::round($MemoryAvailable /1024)).tostring() + “GB”

      So now I get 4GB for $maxRAM variable but once I do that it makes it a “string” type and NOT an “int” type which then won’t allow me to use variable $maxRAM in the following command

      Set-VMMemory -VMName $VMName -DynamicMemoryEnabled $true -MinimumBytes 512MB -MaximumBytes $maxRAM -Buffer 20

      So this part “-MaximumBytes $maxRAM” fails with the following

      Set-VMMemory : Cannot bind parameter ‘MaximumBytes’. Cannot convert value “4GB” to type “System.Int64”. Error: “Input string was not in a correct format.”

      Some assistance to get around this would be much appreciated?

      Thanks

      Shane

    • #270856
      Participant
      Topics: 9
      Replies: 676
      Points: 2,674
      Helping Hand
      Rank: Community Hero

      Just remove the tostring and gb. It wants a number so without it that should work?

    • #270862
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Yes I can do that but I need a command to convert 4 into Bytes (4000000000) . What is the best method doing that?

    • #270889
      Participant
      Topics: 9
      Replies: 676
      Points: 2,674
      Helping Hand
      Rank: Community Hero

      (Get-VMHostNumaNode).MemoryAvailable/4 * 1GB

    • #270895
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      (Get-VMHostNumaNode).MemoryAvailable/4 * 1GB

      That works and has it entered as 4366907998208 which then Hyper-V reports Maximum Memory as 4164608MB. Is there a way to round it off so it’s same as 4GB? in bytes?

      Thanks

    • #270925
      Participant
      Topics: 9
      Replies: 676
      Points: 2,674
      Helping Hand
      Rank: Community Hero

      It’s telling you it wants it in MB plus the documentation does too

      So multiply by 1MB

Viewing 5 reply threads
  • You must be logged in to reply to this topic.