Turbo Tip: Enabling Hot Add on every Virtual Machine Automatically

Document created by swagner Expert on Sep 26, 2016Last modified by swagner Expert on Apr 4, 2018
Version 2Show 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, we can use 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.

 

     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 1.1.1.1 is your vCenter address:

 

Connect-VIServer 1.1.1.1

 

     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, which takes a group of VMs. You can create a group of VMs many ways, but for this example, I can simply use a naming convention:

 

#Create the group

$devVMs = Get-VM dev*

 

#Display the VMs in the group

$devVMs

 

     6. Copy and add the function below to the shell. This script will power every VM down, reconfigure them to allow for hot add, then start them back up:

 

Function hotAdd($vms){

 

      Foreach ($vm in $vms){
            Stop-VM -vm $vm -Confirm:$false
      }

 

      Foreach ($vm in $vms){

            $vmview = Get-vm $vm | Get-view
            $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

 

            $vmConfigSpec.MemoryHotAddEnabled = $true
            $vmConfigSpec.CPUHotAddEnabled = $true

            (Get-View $vm).name

            $vmview.ReconfigVM($vmConfigSpec)
      }

 

      Foreach ($vm in $vms){
            Start-VM -vm $vm -Confirm:$false
      }
}

 

     7. Run the function on a group of VMs, in this example on the group of dev VMs I created:

 

hotAdd -vms $devVMs

 

 

 

 

Remember that these VMs will be power-cycled, so make sure to do it during a maintenance window.

5 people found this helpful

Attachments

    Outcomes