VMware Cloud Community
rubberduck70
Contributor
Contributor

Change number of vCPU's on one or multiple VM's

Hi guys

We are in the process of doing a cleanup operation on some "waste" to decrease the number of vCPU's allocated to certain VM's. The consensus is to perhaps do this in "bulk batches", to import a list of VM's from a CSV file, shut them down, reconfigure with the new spec and power back on. I'm having some issues whereas I found a few commands to do the reconfigure part but keeps on failing:

So the scrip is as follows:

1) #power down commandlets - works 100%#

2)

$vcpu = 2

$NewCPU = Set-VM -VM $vm -NumCpu $vcpu -Confirm:$false

#this then fails as it says that CPU hot plug is not supported for this virtual machine#

3) #power on commandlets - works 100%#

Could you perhaps advise if there is a command to change cores and sockets simultaneously? So basically predefine my cores and sockets somewhere in a variable and then change it for the whole list of VM's?

thanks

0 Kudos
3 Replies
LucD
Leadership
Leadership

Since the Set-VM cmdlet complains about hot-add not being enabled, it looks as if the VM is not actually powered off.

I assume you do a Shutdown-VMGuest in 1), but do you wait till the VM is actually powered off ?

To change the number of CPU and the number of cores, use something like this

For example, 2 processor blocks with each 4 cores

$vm = Get-VM –Name MyVM

$spec=New-Object –Type VMware.Vim.VirtualMAchineConfigSpec –Property @{

    "numCPUs" = 8

    “NumCoresPerSocket” = 4

}

$vm.ExtensionData.ReconfigVM_Task($spec)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
MKguy
Virtuoso
Virtuoso

1) #power down commandlets - works 100%#

2)

$vcpu = 2

$NewCPU = Set-VM -VM $vm -NumCpu $vcpu -Confirm:$false

#this then fails as it says that CPU hot plug is not supported for this virtual machine#

I think you have to re-initialize the $vm object with a new Get-VM after the VM was powered-off. Otherwise the object will still retain the original powered-on state.

Could you perhaps advise if there is a command to change cores and sockets simultaneously? So basically predefine my cores and sockets somewhere in a variable and then change it for the whole list of VM's?

Are you sure you need to set a custom number of cores per socket? Unless you have to for licensing reasons, there is usually no benefit for VMs or performance and you should let ESXi handle it, see:

Does corespersocket Affect Performance? | VMware vSphere Blog - VMware Blogs

Here are some script samples for setting cores per socket:

cpuid.coresPerSocket

-- http://alpacapowered.wordpress.com
0 Kudos
rubberduck70
Contributor
Contributor

Thanks for the speedy response gents

@LucD -> Yep I do a shut down and then sleep for around 10 seconds or until the VM is powered off. I will try and sleep longer to see if it makes a difference as well as use the code provided Smiley Happy

@MKguy -> As per that article, the config should be : number of cores per socket "1" and then just expand / add the number of sockets for the "wide and flat" configuration Smiley Happy. I think I worded it the other way around Smiley Happy

Let me try this out - will keep you guys posted!

0 Kudos