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?
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)
Hello,
Please find the following: VMware PowerCLI Forum - VMware {code}
That only works up to vsphere 6.5. It doesn't work for 6.7
That worked! Thank you!
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?
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)
This does not work for me in 6.7.
Moderator: Moved to PowerCLI
Works for me with this
$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
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.
Also this code works fine if vm is powered off already.
So it works when the VM is powered off? Good. Because that's a requirement.
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?
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
so is there any way to schedule this, similar to the way it works with hardware upgrades "on next reboot"?
Not that I know off.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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?
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
Thanks, LucD!!
That went pretty smooth.
Can we make logging possible here? Like what all VMS have successfully actioned anything as such?