VMware Cloud Community
Boberts
Contributor
Contributor
Jump to solution

Enable VM Hot-Add CPU/Memory on reboot

Hi All,

Does anyone know of a way to automatically enable Hot-Add when a machine is rebooted?  I have been trying to use this script that I found at https://communities.vmware.com/thread/287941:

Function Enable-vCpuAndMemHotAdd($vm){ 

  $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec 

  $extra1 = New-Object VMware.Vim.optionvalue 

  $extra1.Key="mem.hotadd" 

  $extra1.Value="true" 

  $vmConfigSpec.extraconfig += $extra1 

  $extra2 = New-Object VMware.Vim.optionvalue 

  $extra2.Key="vcpu.hotadd" 

  $extra2.Value="true" 

  $vmConfigSpec.extraconfig += $extra2 

  $vm.Extensiondata.ReconfigVM($vmConfigSpec) 

 

Get-Content  "c:\listofvms.txt" | %{ 

   $vm = Get-VM -Name $_ 

   Enable-vCpuAndMemHotAdd $vm  

}

It works great when the VMs are powered off, but does not make the change if they are running.  Does anyone know of a way to modify this script so that the new setting will take effect the next time the VM is rebooted?

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Are you sure about that?

When you use that function to change the settings, the next time you power off/power on the VM (note that is not a Restart Guest OS), the settings will be changed.

If that doesn't work for you, which type of VM (HW version & guest OS) was that?


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

View solution in original post

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

Are you sure about that?

When you use that function to change the settings, the next time you power off/power on the VM (note that is not a Restart Guest OS), the settings will be changed.

If that doesn't work for you, which type of VM (HW version & guest OS) was that?


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

Reply
0 Kudos
Boberts
Contributor
Contributor
Jump to solution

Ah.  That worked.  I had been rebooting rather than shutting down.  Thanks for your help!

Reply
0 Kudos
Noobyy
Contributor
Contributor
Jump to solution

Hello Luc,

I'm diggings the subject, but I've been trying to change the settings on a vCenter 7.X while the VM is poweredOn.

That works when the server is poweredOff but that doesn't work on the next reboot when the server is poweredOn.

If I'm right, that should work doesn't it ?

Thanks a lot.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I'm afraid not, the VM needs to be powered off.


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

Reply
0 Kudos
Noobyy
Contributor
Contributor
Jump to solution

When you've said " [...] the next time you power off/power on the VM (note that is not a Restart Guest OS), the settings will be changed.", I thought we could apply the new setting now, the settings will be in a "waiting" mode until the next reboot and will be commited to the VM configuration only after the reboot.

But I've misunderstood ? 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution


@Noobyy wrote:

But I've misunderstood ? 


No, the condition that the VM needs to be powered off was introduced in more recent vSphere and PowerCLI versions.
In 2017 you could still do it as I described in my reply.


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

Reply
0 Kudos
Noobyy
Contributor
Contributor
Jump to solution

I thought the new capability were added to improve administration, not the other way arround 😅🤣

Thanks a lot Luc !

Reply
0 Kudos