VMware Cloud Community
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?

24 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}


If my reply was helpful, I kindly ask you to like it and mark it as a solution

Regards,
Hassan Alkak
Reply
0 Kudos
eeldivady
Contributor
Contributor

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

Reply
0 Kudos
eeldivady
Contributor
Contributor

That worked!  Thank you!

Reply
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?

Reply
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)

Reply
0 Kudos
jesse_cohen
Enthusiast
Enthusiast

This does not work for me in 6.7.  

Reply
0 Kudos
scott28tt
VMware Employee
VMware Employee

Moderator: Moved to PowerCLI


-------------------------------------------------------------------------------------------------------------------------------------------------------------

Although I am a VMware employee I contribute to VMware Communities voluntarily (ie. not in any official capacity)
VMware Training & Certification blog
Reply
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

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.

Reply
0 Kudos
jesse_cohen
Enthusiast
Enthusiast

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

Reply
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

Reply
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?

Reply
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

Reply
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"?

Reply
0 Kudos
LucD
Leadership
Leadership

Not that I know off.


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

Reply
0 Kudos
ragnarok10
Enthusiast
Enthusiast

Hi LucD

Is there any way we can skip the VM if hotplug is already enabled on it?

Or if the hotplug is already enabled and if we run the script what will be the impact?

 

 

Reply
0 Kudos
LucD
Leadership
Leadership

No impact.
But you could also do

 

$vmName = 'MyVM'

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.CpuHotAddEnabled = $true
$spec.MemoryHotAddEnabled = $true

$vm = Get-VM -Name $vmName

if(-not $vm.ExtensionData.Config.cpuHotAddEnabled -or -not $vm.ExtensionData.Config.memoryHotAddEnabled){
    $vm.ExtensionData.ReconfigVM($spec)
}

 


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

ragnarok10
Enthusiast
Enthusiast

Thanks, LucD!!

 

That went pretty smooth.

Can we make logging possible here? Like what all VMS have successfully actioned anything as such?

 

 

Reply
0 Kudos