BULK upgrading VM’s memory

By | December 20, 2008

Today I had to upgrade all our Jumphost VM’s from 256MB to 512MB of memory (more than 200 VM’s).
There are two ways accomplice this.

1. Do it manually (Very time consuming)

2. Script it with PowerShell

As the lazy person I am I decided that scripting was the way forward.
The script I came up with is as follows:

Connect-VIServer "vi_servername" -User "vi_username" -Password password"

# Select all VM's that have less than 512MB and change the Memory to 512MB
foreach ($vm in Get-VM | Select Name,MemoryMB | Where-Object{$_.MemoryMB -lt "512"}){
Set-VM $vm.Name -MemoryMB "512" -Confirm:$FALSE
}

To suppress the script to prompt for acceptance each time I added the following option
-Confirm:$FALSE

The script easily be changed to add or update other VM hardware settings.
– Number of CPU’s (Set-VM <vm-name> -NumCpu 2)

– Rename VM (Set-VM <vm-name> -Name “NewName”)

Find more options and ideas in the “Automating VMware with PowerShell – Hands-On Lab” from VMworls 2008.

Just remember if a VM is running you have to poweroff or shutdown the VM before the changes will take effect.
This is because a restart or reset does’t reload the vmx file.

Update:

The script is now updates so it also implements the following settings

  • Sets Memory Reservation to half of the amount of ram.
  • Sets Memory Limit to “Unlimited”
  • Sets the VM to check for new VMware Tools on PowerOn.
  • Sets the VM to sync time from host.

Take a look at the scripts here.

Leave a Reply

Your email address will not be published. Required fields are marked *