How to know any VMware object version? Use Get-Version

Cover

Very often I, as well as any virtual infrastructure administrator, you need to know the version of some VMware object. This could be VMTools or vHardware version of virtual machine or a vSphere version of ESXi host or a VMFS version of Datastore, continue the list yourself.

And every time you start to remember how to do it, where to look for or what script to run or start up in a search for forums or the Google.

Get-Version

Function Get-Version from my PowerCLi Vi-Module module once and for all will save you from such problems and will save you a lot of time.

And so, what are the possibilities of Get-Version? At the moment, the function «knows» to work with following objects:

  • ESXi hosts

  • Virtual machines

  • Distributed VSwitches

  • Datastores

  • VCenter servers (Windows/VCSA)

  • PowerCLi framework

  • License keys

ESXi hosts

ESXi hosts can be pipelined to the function by Get-VMHost or Get-View cmdlets:

Get-VMHost | Get-Version
Get-View -ViewType HostSystem | Get-Version

01.Get-Version_Get-VMHost

02.Get-Version_Get-VMHostView

No matter what type of object you pass to the Get-Version, the function always returns objects with the same properties:

Property Description
ProductName Object name
ProductType Object type (VMHost, Datastore, VCenter etc.)
FullVersion Object version’s full name
Version Version itself

Version property

  • Special attention should be the Version property. Unlike the first three, the Version property is not a plain text, but also an object of type [System.Version].
[System.Version]6.5 | Get-Member
[version]’6.5.1’ | Get-Member

03.Get-Version_VersionType

  • This is done for convenience in version comparison. After all, the current version itself does not interest anyone, it makes sense in comparison with any given version only.

  • For example, you want to know how many ESXi hosts with a version lower than 5.5 do you have, or how many of these hosts have revision below 2456374. With Get-Version it’s very simple.

Get-VMHost | Get-Version | ? {$_.Version –lt 5.5}
Get-VMHost | Get-Version | ? {$_.Version.Major –lt 5}
Get-VMHost | Get-Version | ? {$_.Version -ge 5.5 -and $_.Version.Revision -lt 2456374}

04.Get-Version_Get-VMHostFiltered

Virtual machines

Every VM has already three important versions – a version of Virtual Hardware, VMTools version (if installed) and the name + version of the operating system VMGuest version.

To fit it all into the structure of the returned object, I had to do so:

Property Description
ProductName VM name
ProductType OS name (GuestFullName)
FullVersion vHardware version (v7, v11 etc.)
Version VMTools version
Get-VM | Get-Version | ? {$_.FullVersion -match '\d{2}' -and $_.Version -gt 9.1}

05.Get-Version_Get-VM

Distributed Virtual Switches

By default, the DVSwitch version matches the version of VCenter on which it was created, but after migrations could remain previous versions of VDSwitch.

Get-VDSwitch | Get-Version | sort Version

06.Get-Version_Get-DVSwitch

With Get-Version it is very easy to find them.

Get-VDSwitch | Get-Version | ? {$_.Version –lt 5.5} | sort Version

07.Get-Version_Get-DVSwitchFiltered

Datastores

A Datastore itself does not have any version, but its VMFS does have one:

Get-Datastore | Get-Version
Get-Datastore | Get-Version | ? {$_.Version.Major -eq 3}

08.Get-Version_Get-Datastore

Version comparison

  • A few rules you should know about version comparison, and more specifically the values comparison of [System.Version] data type. Not knowing these rules, you can get incorrect results when comparing versions!

  • Here is the great example to understand it:

Let’s say you need to find all datastores with VMFS version lower than 5.6. It would seem simple. You and I understand that the version 5.6 > 5.54, and it is not discussed Emoj. But take a look what the results will give you Mr. PowerShell.

[System.Version]5.54 -gt [System.Version]5.6
True
  • Surprised? Not yet? Okay, well, let’s say that 5.6 < 5.54 because of 6 < 54. Let’s add a zero, so 60 greater than 54 for sure. But now you will definitely be surprised. Version 5.60 as 5.6 is still less than 5.54!!!
[System.Version]5.54 -gt [System.Version]5.60
True

09.Get-Version_Compare-Versions

There are two ways to avoid such mistakes:

  • Convert Version property to the [string] data type before you compare.
[System.Version]’5.54’ -gt [System.Version]’5.60’
False
([System.Version]5.54).ToString() -gt ([System.Version]5.60).ToString()
False

Get-Datastore | Get-Version | ? {$_.Version.ToString()-gt 5.54}
  • Compare major and minor versions separately (as you can see on the previous picture). In my opinion this method is more reliable, the choice is yours.
Get-Datastore | Get-Version | ? {$_.Version.Major-eq 5 –and $_.Version.Minor –lt 60}

VCenters

  • To determine the version of VCenter(s), you must first connect to it/them using Connect-VIServer cmdlet and then run the Get-Version with -VCenter parameter.
Connect-VIServer VC5, VCSA1, PSC1 -WarningAction SilentlyContinue
Get-Version –VCenter

10.Get-Version_VCenter-Connected

  • Please note that in addition to five VCenters, I directly connected to one ESXi host, which also in the list.

  • As a bonus you will get the PowerCLi version of your computer (always will be the last line).

  • In case you still nowhere connected, you will get the PowerCLi version only.

11.Get-Version_VCenter-Disconnected

  • In the ProductType property you will also get information about VCenter server’s platform (Windows or Appliance).

12.Get-Version_VCenter-VCSA

  • If for any reason you were disconnected from VCenter, for example, session timeout, network issues, VCenter restart, etc., you will get the following:

13.Get-Version_VCenter-Timeout

  • To correct this, reconnect to the VCenter. This is done for a reason, if while the session was disconnected you have upgraded your VCenter.

License keys

  • To get VMware products license keys version you should run Get-Version with -LicenseKey switch.
Get-Version –LicenseKey

14.Get-Version_LicenseKey

  • Here you will also get a small bonus in the FullVersion property. You get license key usage statistics in the following format [used/total license cost units], for example [160/200CPU].

  • When dealing with license keys you need to consider one feature. If you are in the same session connected to VCenter server and ESXi host or hosts, that using one of the keys from this VCenter, then such keys will appear twice or more, but with different statistics:

15.Get-Version_DuplicateLicenseKey

  • For more details about the function, please take a look at the content based help and examples.
Get-Help Get-Version –Examples
Get-Help Get-Version –Full
Get-Help Get-Version –Parameter VCenter

Summary

If you think that I missed any important VMware object(s), which version is important to know, please write in the comments, I will try to add.

4 thoughts on “How to know any VMware object version? Use Get-Version

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 )

Google+ photo

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

Connecting to %s