Adding CPU'sSometimes you need to add CPUs to your virtual machines. Adding CPU’s is easy on a virtual machine. Of course you can do this from the vSphere Client, where you can select the number of CPUs and the number of cores per CPU. If you only need to change one virtual machine this isn’t a problem. When you have to change 50 virtual machines it gets somewhat tiresome.

Luckily we can use PowerCLI for that. With the cmdlet Set-VM you can change all kinds of parameters of the virtual machine. The command below gets a VM object and changes the number of CPUs.

sets the number of CPU’s for this VM to two. It asks you if you’re sure.

This way you add 2 CPU’s (sockets) to the virtual machine with each one core. If you want to add CPU’s with multiple cores you need to do something extra.

Make sure that NumCPU is the total number of cores you want. If you want 2 CPU’s with 2 cores you set NumCPU to 4.

Removing the CPU’s

Of course you can also remove the CPU’s again from the virtual machine. You just set the number to a lower quantity. If you need to reduce the core count, use the $VMSpec part above with NumCoresPerSocket set to 1.