Mass-VDI reconfiguration on vSphere with PowerCLI
A colleague asked me if there was an easy way to reconfigure VM´s that was on different hosts with PowerCLI, for some reason the VM´s had been configured with too many vCPU´s and the customer wanted a way to reconfigure the running VM´s.
I made a very easy PowerCLI script to solve this, maybe there is other solutions that might be better/more beautiful but this one solved the issue 🙂
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Configure vCPU on VDI VM´s with PowerCLI # configure-CPU.ps1 # # 20150126 # Author : Niklas Åkerlund vniklas.com param( $vmhost, $vdi, $vCPU=2 ) $vmhost = Get-VMHost -Name $vmhost $vdiVMs = $vmhost | Get-VM "$vdi*" $vdiVMs | foreach {Shutdown-VMGuest -VM $_ -Confirm:$false} Start-Sleep -Seconds 20 $vdiVMs | ForEach{Set-VM -VM $_ -NumCpu $vCPU -Confirm:$false} $vdiVMs | Foreach{Start-VM -VM $_} Get-VM "$vdi*" | Select-Object Name,NumCpu |
You save this as a script and then run it with the starting name of the VM´s you want to configure, and as you can see you have to already have connected to the vcenter with Connect-VIServer before running it:

happy automating 🙂