Quick PowerCLI- Getting VM hardware versions

A quick PowerCLI snippet for examining what VM Hardware versions exist in your virtual environment:

Using the “Group-Object” cmdlet we can run up a quick count of all the VMs on each hardware version

 1Get-VM | Group-Object Version
 2
 3Count Name                      Group
 4----- ----                      -----
 542    v13                       {VM1,VM2,VM3...}
 6257   v8                        {VM4,VM5,VM6...}
 770    v11                       {VM7,VM8,VM9...}
 82     v4                        {VM10,VM11}
 95     v10                       {VM12,VM13,VM14...}
102     v9                        {VM15,VM16}
112     v7                        {VM17,VM18}

This can be refined using “Sort-Object” to put the most common hardware version at the top of the list.

 1Get-VM  | Group-Object Version | Sort-Object Count -Descending
 2Count Name                      Group
 3----- ----                      -----
 4257   v8                        {VM4,VM5,VM6...}
 570    v11                       {VM7,VM8,VM9...}
 642    v13                       {VM1,VM2,VM3...}
 75     v10                       {VM12,VM13,VM14...}
 82     v7                        {VM17,VM18}
 92     v9                        {VM15,VM16}
102     v4                        {VM10,VM11}

We may only be concerned with VMs that are Powered On, so “Where-Object” can be used to filter the original list.

1Get-VM  | Where-Object {$_.PowerState -eq "PoweredOn"} | Group-Object Version | Sort-Object Count -Descending
2Count Name                      Group
3----- ----                      -----
466    v8                        {VM4,VM5,VM19...}
551    v11                       {VM7,VM8,VM9...}
633    v13                       {VM1,VM21,VM22...}
75     v10                       {VM12,VM13,VM20...}
82     v9                        {VM15,VM16}
91     v4                        {VM10}

This quick snippet can be useful when establishing the range of hardware versions in an environment, or estimating the amount of work involved in updating VM hardware to a modern standard across an estate.


Update November 2021

If you run the above code on a modern vSphere environment you may get a warning that the Version property is now deprecated and some of the VMs may be listed with an unknown version name.

1Get-VM  | 
2    Where-Object {$_.PowerState -eq "PoweredOn"} |
3    Group-Object Version |
4    Sort-Object Count -Descending
1WARNING: The 'Version' property of VirtualMachine type is deprecated. 
2    Use the 'HardwareVersion' property instead.

So instead, follow the advice and use HardwareVersion instead:

1Get-VM  | 
2    Where-Object {$_.PowerState -eq "PoweredOn"} |
3    Group-Object HardwareVersion |
4    Sort-Object Count -Descending

And results will look something like this:

1Count Name      Group
2----- ----      -----
366    vmx-08    {VM4,VM5,VM19...}
451    vmx-11    {VM7,VM8,VM9...}
533    vmx-13    {VM1,VM21,VM22...}
65     vmx-15    {VM12,VM13,VM20...}