Enable Hot CPU and Hot Memory Add Feature with PowerCLI

Hello all,

One of my colleague looking for a PowerCLI script that is enabling Hot Add CPU and Hot Add Memory feature on listed VMs. He did quite lot search on google and find out couple of scripts but some of them partially run on vCenter 7.0. So, I merged the most useful ones and we have a PowerCLI script that enables Hot Add CPU and Memory features on list of VMs that we can provide in a txt file. I tested on my environment and it works fine as of now.

I want to reiterate that I did not write this PowerCLI code but I just merged working part of different scripts. You can find the script that includes the function. I want to thanks again who created these PowerCLI scripts and hope this would be help others 🙂

PS: listofvms.txt file should includes the VM names that you want to enable Hot CPU and Hot Memory Add Feature. Also, to enable these features VMs should be powered off.

Function Enable-HotAdd($vmName){
$vm = Get-VM $vmName
if ( $VM.PowerState -eq “PoweredOff” ) {
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.memoryHotAddEnabled = $true
$spec.cpuHotAddEnabled = $true
$vm.ExtensionData.ReconfigVM_Task($spec)
}
else { write-host “Cannot enable hot-add with VM powered-on.” }
}

Get-Content “c:\scripts\listofvms.txt” | %{

$vm = Get-VM -Name $_

Enable-HotAdd $vm
}

You may also like...