PowerCLI command to show CPU and memory ‘Hot Add’ status for VMs

I had an interesting request from a customer to list the CPU and memory ‘Hot Add’ status for their VMs. All of their VMs were in a single vCenter datacenter so we could query that object for the relevant info. After a bit of hacking I came up with the following PowerCLI one-liner:

get-datacenter DataCenterName | Get-VM | Get-View | Select Name, @{N="CpuHotAddEnabled";E={$_.Config.CpuHotAddEnabled}}, @{N="CpuHotRemoveEnabled";E={$_.Config.CpuHotRemoveEnabled}}, @{N="MemoryHotAddEnabled";E={$_.Config.MemoryHotAddEnabled}} | export-csv C:\HotAddVMs.csv

The command yielded the required information and was duly forwarded to the customer.