Retrieve VM Memory and CPU Hot Add information from PowerCLI

I was recently looking to return VMs where the ‘Enable memory hot add information for this virtual machine’ was not configured. For a single VM, you can view this information from selecting ‘Edit Settings > Options > Memory/CPU Hotplug’  as below:

 

HotPlug

 

 

 

 

 

 

 

 

 

From PowerCLI you can retrieve this information by using the Get-View cmdlet to return the the VM names which do not have the ‘Enable memory hot add for this virtual machine’ setting Enabled, by filtering the property ‘Config.MemoryHotAddEnabled’ where the value is equal to ‘False’ and return only the VM name:

(Get-VM | Get-View | Where-Object {$_.Config.MemoryHotAddEnabled -eq "False"}).Name 

A similar approach can be used to retrieve the status of the CPU Hot Plug configuration, we can determine if Enable CPU hot add and remove for this virtual machine has been configured for VMs by running:

(Get-VM | Get-View | Where-Object {$_.Config.CpuHotRemoveEnabled -eq "True"}).Name

As you can see the state of the configuration is expressed in a True or False statement, in order to retrieve VMs where the ‘Enable CPU hot add only for the virtual machine’ is not enabled, you would run the following:

(Get-VM | Get-View | Where-Object {$_.Config.CpuHotAddEnabled -eq "False"}).Name

Now if I want to return the status of all the configurations above and export to a file, I could run the following script  to retrieve the state of each configuration and output the information to a comma separated values text file.

# Adds snap-ins to the current powershell session for vSphere Power CLI.
If (-not (Get-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) 
    {
    Add-PSSnapin VMware.VimAutomation.Core > $null
    }
# Connect to VIServer 
Connect-VIServer server1.domain.local

# Retrieves the vSphere objects for all virtual machines 
$VMs = (Get-VM | Get-View) 

# Retreives Memory and CPU Hot Add configuration and exports to a CSV. 
$Output = ForEach ($VM in $VMs)
    {  `
    "" | Select @{N="Name";E={$VM.Name}},
    @{N="Memory Hot Add Enabled";E={$VM.Config.MemoryHotAddEnabled}},
    @{N="CPU Hot Add Enabled";E={$VM.Config.CpuHotAddEnabled}},
    @{N="CPU Hot Add and Remove Enabled";E={$VM.Config.CpuHotRemoveEnabled}}
    }
$Output | Export-Csv -Path D:\Output\MemoryCPUHotAdd.csv -NoTypeInformation

 


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s