VMware Cloud Community
crawfordm
Expert
Expert

Script to set memory reservation on all vm's

I am trying to write a script that will set a memory reservation on all vm's to what the vm memory is.  This way all swap files will be 0.

I am not sure of $_.MemoryMB will give me the correct setting.

$vm = Get-VM
foreach ($vm_single in $vm)
    {Get-VMResourceConfiguration | Set-VMResourceConfiguration -MemReservationMB $_.MemoryMB
    }
Get-VMResourceConfiguration -VM $vm_Single | Select -ExpandProperty DiskResourceConfiguration
Thanks
Marc
------------------------------------------------------------------ If you found this answer useful please consider the use of the Helpful or Correct buttons to award points. Thanks, Marc Crawford CCNA, MCSE, MCTS, A+, Net+, Sec +, VCA-WM, VCA-DCV, VCA-Cloud, VCA-NV, VCP-NV, VCP-DCV, VCP, VCAP5-DCA http://gplus.to/marccrawford http://blog.marccrawford.com @uber_tech_geek
Reply
0 Kudos
1 Reply
RvdNieuwendijk
Leadership
Leadership

Hi Marc,

you are correct about the MemoryMB property.Only in your case you should use $vm_single.MemoryMB. However the Set-VMResourceConfiguration -MemReservationMB parameter is obsolete. Use MemReservationGB instead:

foreach ($vm in (Get-VM))
{
  Get-VMResourceConfiguration |
  Set-VMResourceConfiguration -MemReservationGB $vm.MemoryGB
}

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition