eeldivady
Contributor
Contributor

How to set hotadd memory or cpu using Powercli in Vsphere 6.7

https://davidstamen.com/2015/01/14/powercli-enable-cpu-and-memory-hotadd/

I've found this method to set hotadd using Powercli but it only works up to Vsphere 6.5.  It doesn't work for latest 6.7 and I can't find any resource online how to fix this.  I've tried older versions of Powercli as well as latest Powercli 11.3 but nothing works and no errors when running this script.  I've tried rebooting or leaving the VM powered off when running it but nothing works on Vsphere 6.7.  Anyone have any ideas?  Is there a new cmdlet in PowerCli I should use?

16 Replies
MartinGustafsso
VMware Employee
VMware Employee

Hi,

You can try this.

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.CpuHotAddEnabled = $true

$spec.DeviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[] (0)

$spec.MemoryHotAddEnabled = $true

$spec.CpuFeatureMask = New-Object VMware.Vim.VirtualMachineCpuIdInfoSpec[] (0)

$_this = Get-View -Id 'VirtualMachine-vm-189'

$_this.ReconfigVM_Task($spec)

HassanAlKak88
Expert
Expert

Hello,

Please find the following: VMware PowerCLI Forum - VMware {code}


Cheers,
vExpert2020-2019||vExpert-NSX2020||VCIX6-NV||VCAP-NV-DCV||VCP-NV-DC-CMA||CCNA-R&S
Twitter: @KakHassan
LinkedIn: linkedin.com/in/hassanalkak
0 Kudos
eeldivady
Contributor
Contributor

That only works up to vsphere 6.5.  It doesn't work for 6.7

0 Kudos
eeldivady
Contributor
Contributor

That worked!  Thank you!

0 Kudos
eeldivady
Contributor
Contributor

Thank you so much for your help.  Could you tell me what CpuFeatureMask and DeviceChange does?  I think DeviceChange is required if we modify cpu or memory hotadd.  But CpuFeatureMask is only required if I only change the cpu hotadd value.  Is that correct?

0 Kudos
eeldivady
Contributor
Contributor

I notice the code works without these two lines so could you please tell me their purpose and why it's needed?

$spec.DeviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec[](0)

$spec.CpuFeatureMask = New-Object VMware.Vim.VirtualMachineCpuIdInfoSpec[](0)

0 Kudos
jesse_cohen
Enthusiast
Enthusiast

This does not work for me in 6.7.  

0 Kudos
scott28tt
VMware Employee
VMware Employee

Moderator: Moved to PowerCLI

0 Kudos
LucD
Leadership
Leadership

Works for me with this

$vmName = 'MyVM'

$vm = Get-VM -Name $vmName


$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.CpuHotAddEnabled = $true

$spec.MemoryHotAddEnabled = $true


$vm.ExtensionData.ReconfigVM($spec)

Are you getting any errors?


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

0 Kudos
jesse_cohen
Enthusiast
Enthusiast

no errors, it looks like it works, I see a configuration task in vmware.  However if I check the check box it is not checked and if I power off/ back on it still is not checked after running the script.

0 Kudos
jesse_cohen
Enthusiast
Enthusiast

Also this code works fine if vm is powered off already.

0 Kudos
MartinGustafsso
VMware Employee
VMware Employee

So it works when the VM is powered off? Good. Because that's a requirement. Smiley Happy

Enable CPU Hot Add

0 Kudos
jesse_cohen
Enthusiast
Enthusiast

OK my mistake by replying to this thread then.  I am trying to find a way to do this for a whole lot of vms without having them all powered down already.  I have read some posts that claimed this would work when powered on but then still required a power off to take effect.  Is this not the case?

0 Kudos
LucD
Leadership
Leadership

It will not work when the VM is powered on.
That is one of the prereqs listed in Enable CPU Hot Add

The option is also disabled in the Web Client when the VM is powered on.


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

0 Kudos
jesse_cohen
Enthusiast
Enthusiast

so is there any way to schedule this, similar to the way it works with hardware upgrades "on next reboot"?

0 Kudos
LucD
Leadership
Leadership

Not that I know off.


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

0 Kudos