Using PowerCLI VIProperties and the VIProperty Module

In PowerShell it is possible to use custom properties for an object if the one you need does not exist by default - these are known as calculated properties.

For instance, in PowerCLI by default there is no ToolsVersion property for a VM, however we can create a calculated property named ToolsVersion and submit an expression to retrieve that data:


Get-VM TEST01 | Select-Object Name,@{Name="ToolsVersion";Expression={$\_.ExtensionData.Config.Tools.ToolsVersion}}

However, the ToolsVersion property does not persist after running this command, so if I now try:


Get-VM TEST01 | Select-Object Name,ToolsVersion

The ToolsVersion is not returned since PowerShell is not aware of that property. I would need to specify the expression again if I wanted to use it.

PowerCLI 4.1 introduced the new cmdlet New-VIProperty which allows you to create custom properties for an object. However, these properties will persist for the course of the current PowerShell session. Using the same example as above we can create a ToolsVersion property like this:


New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine  -ValueFromExtensionProperty 'config.tools.ToolsVersion’ -Force

So now I can run this query and this time I will get the results I was hoping for:


Get-VM TEST01 | Select-Object Name,ToolsVersion

The possibilities for using  New-VIProperty are almost limitless. Luc Dekens has done a great job of collating a large set of community efforts of these on his VIProperties page . I have been using them a lot recently, either those already submitted, or creating my own, but was finding it frustrating copy / pasting each one in as and when required.

So instead I decided to put them all into a PowerShell module so that each of them would be potentially available at any time, simply by importing the module. A PowerShell module can be as simple as a collection of functions or scripts that are bundled up together and then imported to make them available for use.

I sent this to Luc, he thought it was a good idea too. So after tidying it up a bit, you can now download it from his site . Once downloaded and before unzipping the files, make sure to unblock the content before extracting it, otherwise you will have an issue when importing the module, dependent on your current PowerShell Execution policy:

Copy the extracted VIProperty folder to your PowerShell modules location - you can find this with:


$env:PSModulePath

Now you can make all of those VIProperties available by importing the module:


Import-Module -Name VIProperty

For instance I could combine some standard (Name, NumCPU) and custom properties (BootDelay,NumVirtualDisks) from the module  in this query:


Get-VM Test01 | Select-Object Name,NumCPU,BootDelay,NumVirtualDisks

I highly recommend PowerCLI users check this out and please help make the module even more useful by submitting your own custom properties to Luc for inclusion.