Increasing the amount of vCPUs in ESXi is a simple admin task when working with a single or low number of virtual machines. However, performing this on a large number of virtual machines can be an intensive task.
This article is about my use case and how I resolved this with a script, which can be found at the bottom.
In my case, a customer was expanding their VDI cluster and increasing virtual machine vCPU capacity from 2 to 4. Besides of this, the configuration required a 2 socket – 2 core (4 vCPU) setup.
The script I wrote for this, assumes the virtual machines you want to modify are powered off and modifies all virtual machines on the selected ESXi host. Of course you can modify the parameters to have a selection based on virtual machine name or to exclude specific virtual machines.
The script logs any actions to the $LogFile file, for historical/troubleshooting references.
Make sure you test the script on a non-production environment first. I am not responsible for any negative outcomes by using this script.
Write-Host "Getting current VM configuration"
Write-Host "These VMs are currently not powered off and will not be reconfigured"
Write-Host "Reconfiguring powered off VMs with 4 vCPUs"