PowerShell Scripting & Hyper-V PoC RRS feed

  • General discussion

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



    Wednesday, November 11, 2020 10:57 PM

All replies