The other night I had a task of upgrading 22 VMs with additional vCPUs and memory. I also had a maintenance window of 60 minutes to get this completed. So I wasn’t going to do this more than once, so I just wrote a simple PowerCli script that would handle this process for me.
$servers = "VMServer01","VMServer02","VMServer03","VMServer04","VMServer05" foreach ($server in $servers){ Shutdown-VMGuest $server -confirm:$false Do { sleep -Seconds 5 $Status = (Get-vm $server).powerstate If($status -eq "PoweredOff") {"$Server has been powered off adding hardware"} else{ "$server is still powered on looping until off" } } While ($Status -eq "PoweredOn") $TotalvCPU=6 $Cores=1 $VMname = get-vm $server $spec=New-Object –Type VMware.Vim.VirtualMAchineConfigSpec –Property @{“NumCoresPerSocket” = $cores} ($VMname).ExtensionData.ReconfigVM_Task($spec) $VMname | Set-VM -MemoryGB 28 -NumCpu $TotalvCPU -Confirm:$false Sleep -Seconds 5 Start-VM $server -Confirm:$false }
So this script starts off identifying the servers that the work is going to be performed on.… Continue reading