Turbo Tip: Enabling Hot Add on every Virtual Machine Automatically

Document created by swagner on Sep 26, 2016
Version 1Show Document
  • View in full screen mode

I have been working with several Sys Admins who had some issues with pushback on rightsizing VMs, and had a ton of CPU Ready building up in their environments as a result of greedy coworkers. In order to get their blessing on rightsizing down during a maintenance window, I wrote this PowerCLI function to enable Hot Add for all their VMs automatically so that if their applications spiked in demand during the week, we can add it on the fly.


This approach to Datacenter management has received great feedback, and the nice thing about executing this function is that it includes VMs that are on, and the Hot Add feature will be enabled and take effect whenever the VM is restarted by you. Let's start:


     1. Download, install, and run PowerCLI. As a side note, PowerCLI has the same syntax as PowerShell

     2. Connect to your vCenter, where in this example is your vCenter address:




     3. In 10 seconds or so, a login window will pop up, use your vCenter credentials here

     4. In 5 seconds after that, it will show that you connected to your vCenter via port 443

     5. Below, I wrote a function to enable Hot Add for both Mem and CPU, on a cluster-by-cluster basis. If you want to start with a cluster, you can look up you cluster names by running:




     6. Copy and add the function below to the shell:


Function hotAdd($cluster){


      $vms = Get-Cluster $cluster | Get-VM

      Foreach ($vm in $vms){


           $vmview = Get-vm $vm | Get-View

           $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec


           $extra1 = New-Object VMware.Vim.optionvalue




           $extra2 = New-Object VMware.Vim.optionvalue




           (Get-View $vm).name






     7. Run the function on a cluster, in this example both of my test01 and test02 clusters:


hotAdd -cluster test*


     8. It will run through each VM in the cluster(s), taking about 3 seconds for each VM. It will print the name of the VM in the shell it attempts to change, and you will see a “Reconfigure VM” in the vCenter logs. Hit Ctrl-C if you want to force-stop

     9. If there are VMs you don’t want to include, for example, only wanting to do this on Windows VMs, you can insert an if statement after the Foreach:


Foreach ($vm in $vms){


        if ((Get-View $vm).Guest.GuestFamily -match "windows"){

            $vmview = Get-vm $vm | Get-View






This has worked very well with everyone I’ve run through this with, so this will help you out a ton. Remember that VMware Tools need to be installed, but if the function runs into one without it, it will simply be skipped over. And again, you can do this on all VMs, on or off, and while it will only take effect once the VM is powered-off, Hot-Add will still be enabled so you don’t need to turn each VM off!


Happy automating!

4 people found this helpful