Exploring Extended Properties in PowerCLI
I was asked recently via Twitter how to find the CpuFeatureMask property of a VM using PowerCLI. When running a basic
Get-VM Test01
the below properties are outputted to the console:
It is possible to view more properties and values by runnning:
Get-VM Test01 | Format-List \*
Unfortunately this still does not reveal the CpuFeatureMask property. However, if we pipe the Get-VM command through to Get-View we will get back a .NET view object for the VM - by saving this into a variable we can then drill down through the various levels and look for the property we need.
$vm = Get-VM | Get-View $vm
Below is the top level of information which is returned:
This may look initially like a bewildering amount of info, however if you look at the first few entries you could treat them like categories of information. Since CpuFeatureMask is a configuration property it would seem like a good guess to try looking in the Config category:
You can essentially browse this category by entering the following
$vm.config
and looking down the list of properties returned you will see CpuFeatureMask
On this particular VM CpuFeatureMask is not set, but you get the idea. To retrieve this property for all of your VMs is a simple one liner. With Select-Object we can pick one of the standard properties Name by simply specifiying it; we can use another technique to create our own property with a label and expression for the CpuFeatureMask.
Get-VM | Get-View | Select-Object Name,@{Name="CpuFeatureMask";Expression={$\_.config.CpuFeatureMask}}
You could apply a similar technique to other cmdlets like Get-Host or Get-Cluster to retrieve non-standard properties.