PowerCLI - Enable CPU and Memory HotAdd

Share on:

I had a need to enable CPU and Memory hotadd to many virtual machines prior to a template being updated, doing some research there is no easy way, however there are some functions out there to do it. You can copy and paste each function into a powershell window and then run the associated command.

1Enable-MemHotAdd $ServerName
2Disable-MemHotAdd $ServerName
3Enable-vCPUHotAdd $ServerName
4Disable-vCPUHotAdd $ServerName

Enable Memory HotAdd

1Function Enable-MemHotAdd($vm){
2$vmview = Get-vm $vm | Get-View
3$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
4$extra = New-Object VMware.Vim.optionvalue
5$extra.Key="mem.hotadd"
6$extra.Value="true"
7$vmConfigSpec.extraconfig += $extra
8$vmview.ReconfigVM($vmConfigSpec)
9}

Disable Memory HotAdd

1Function Disable-MemHotAdd($vm){
2$vmview = Get-VM $vm | Get-View
3$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
4$extra = New-Object VMware.Vim.optionvalue
5$extra.Key="mem.hotadd"
6$extra.Value="false"
7$vmConfigSpec.extraconfig += $extra
8$vmview.ReconfigVM($vmConfigSpec)
9}

Enable CPU HotAdd

1Function Enable-vCpuHotAdd($vm){
2$vmview = Get-vm $vm | Get-View
3$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
4$extra = New-Object VMware.Vim.optionvalue
5$extra.Key="vcpu.hotadd"
6$extra.Value="true"
7$vmConfigSpec.extraconfig += $extra
8$vmview.ReconfigVM($vmConfigSpec)
9}

Disable CPU HotAdd

1Function Disable-vCpuHotAdd($vm){
2$vmview = Get-vm $vm | Get-View
3$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
4$extra = New-Object VMware.Vim.optionvalue
5$extra.Key="vcpu.hotadd"
6$extra.Value="false"
7$vmConfigSpec.extraconfig += $extra
8$vmview.ReconfigVM($vmConfigSpec)
9}

Notes: Enabling CPU Hotadd disables vNUMA. So enable enable this if its really neccessary in your environment.

KB2040375

comments powered by Disqus

See Also