Figuring out what build of ESX or ESXi VMware Tools maps to for VMs using PowerCLI

 

This evening I was spending a bit of extra time checking through various components of a vSphere 4 installation to see what was compatible with ESXi 5 and what was not. As you would expect VMware Tools and Hardware needs to be checked for Virtual Machine compatibility with ESXi 5. There are plenty of scripts in PowerCLI out there that will show you how to determine the VMware Tools version, but this is always reported back as a four digit “cryptic” number, which doesn’t make much sense unless you go look it up.

 

In my quest to make this easier, I wrote a quick PowerCLI Function that will report back with some (hopefully) helpful information – it lists the Virtual Machine, Virtual Machine Tools version number as well as what version of ESX or ESXi + the update level that version of VMware Tools maps to. In my quest to make this easier for myself, I stumbled across this VMware Version mapping-file. Within it, contained the answers to the various VMware Tools version “codes” that were easy enough to retrieve with PowerCLI. My function simply does a quick check to see if the Tools number on a VM matches any of these codes and then lists the mapped version of ESX(i) corresponding to the code next to the VM.

 

So without going on in any further detail, here is an example of the output from a cluster I ran my function on (interesting I spot an ESX 3.5 VMware Tools VM in there!):

 

 

I think this will be a very useful little Function to have handy for these kinds of checks – especially larger infrastructures where VM tools are not known to be 100% up to date! The great thing about this is you can pipe in VMs. In the example above, I have grabbed all the VMs in a certain cluster and checked those using Get-Cluster and Get-VM, piping the output of those cmdlets to my Get-VMToolsMapped Function. Here is the script download:

 

[download id=”12″]

 

# Mapping file found at: http://packages.vmware.com/tools/versions
# Content of mapping file as of 08/03/2012:

Function Get-VMToolsMapped() {

 Get-VMToolsMapped -VM MYVMNAME

.EXAMPLE
PS F:\> Get-VMToolsMapped MYVMNAME

.EXAMPLE
PS F:\> Get-VM | Get-VMToolsMapped

.EXAMPLE
PS F:\> Get-Cluster "CLUSTERNAME" | Get-VM | Get-VMToolsMapped

.LINK
http://www.shogan.co.uk

.NOTES
Created by: Sean Duffy
Date: 08/03/2012
#>

[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=$true,HelpMessage="Specify the VM name you would like to query VMware Tools info for.",
ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[String]
$VM
)

process {

$Report = @()
New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine -ValueFromExtensionProperty 'config.tools.ToolsVersion' -Force

$VMInfo = Get-VM $VM | Select Name, ToolsVersion
Switch ($VMInfo.ToolsVersion) {
	8389 {$ESXMapping = "esx/5.0u1"}
	8384 {$ESXMapping = "esx/5.0"}
	8300 {$ESXMapping = "esx/4.1u2"}
	8295 {$ESXMapping = "esx/4.1u1"}
	8290 {$ESXMapping = "esx/4.1"}
	8289 {$ESXMapping = "esx/4.1"}
	8288 {$ESXMapping = "esx/4.1"}
	8196 {$ESXMapping = "esx/4.0u4 or esx/4.0u3"}
	8195 {$ESXMapping = "esx/4.0u2"}
	8194 {$ESXMapping = "esx/4.0u1"}
	8193 {$ESXMapping = "esx/4.0"}
	7304 {$ESXMapping = "esx/3.5u5"}
	7303 {$ESXMapping = "esx/3.5u4"}
	7302 {$ESXMapping = "esx/3.5u3"}
	default {$ESXMapping = "Unknown"}
	}

$row = New-Object -Type PSObject -Property @{
   		Name = $VMInfo.Name
		ToolsVersion = $VMInfo.ToolsVersion
		ESXMapping = $ESXMapping
	}
$Report += $row
return $Report

}
}

 

PS – big thanks to @alanrenouf and @jonathanmedd for pointing out the much more efficient PowerShell “Switch” statement – I have updated the script above to use this and saved quite a few lines of code in the process.

 

6 thoughts on “Figuring out what build of ESX or ESXi VMware Tools maps to for VMs using PowerCLI”

  1. I just came across this pretty cool function but my results look a little different from the shown screen shot, I suspect this has something to do with the fact that I am running Powershell 3.0 and PowerCLI 5.1 Release 1.

    I am new to Powershell and PowerCLI, can someone tell me what I need to do to have the output formatted as the shown screen shot? Below is the output I am getting.

    thank you,

    PowerCLI H:\> get-vm virtualmachinename | get-vmtoolsmapped

    Name RetrievingType DeclaringType Value
    —- ————– ————- —–
    ToolsVersion VirtualMachine VirtualMachine config.tools.ToolsVersion

    Name : virtualmachinename
    ToolsVersion : 9216
    ESXMapping : esx/5.1

  2. Hi Datto,

    I see the issue – the function is not loaded into your current PowerCLI session, so basically you can either, a) set it up to auto load whenever you run PowerCLI and therefore have it ready for any PowerCLI session, or b) load it manually into your current session (copy-paste into PowerCLI).

    to do a) run the following in any powerCLI session:

    notepad.exe $profile

    Notepad will launch and open your user’s powershell profile copy and paste the script in this post without the notes and examples section into your profile in notepad and save the file. To save you dissecting, here is what you need to copy in:

    Function Get-VMToolsMapped() {

    [CmdletBinding()]
    param(
    [Parameter(Position=0,Mandatory=$true,HelpMessage=”Specify the VM name you would like to query VMware Tools info for.”,
    ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
    [String]
    $VM
    )

    process {

    $Report = @()
    New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine -ValueFromExtensionProperty ‘config.tools.ToolsVersion’ -Force

    $VMInfo = Get-VM $VM | Select Name, ToolsVersion
    Switch ($VMInfo.ToolsVersion) {
    8389 {$ESXMapping = “esx/5.0u1”}
    8384 {$ESXMapping = “esx/5.0”}
    8300 {$ESXMapping = “esx/4.1u2”}
    8295 {$ESXMapping = “esx/4.1u1”}
    8290 {$ESXMapping = “esx/4.1”}
    8289 {$ESXMapping = “esx/4.1”}
    8288 {$ESXMapping = “esx/4.1”}
    8196 {$ESXMapping = “esx/4.0u4 or esx/4.0u3”}
    8195 {$ESXMapping = “esx/4.0u2”}
    8194 {$ESXMapping = “esx/4.0u1”}
    8193 {$ESXMapping = “esx/4.0”}
    7304 {$ESXMapping = “esx/3.5u5”}
    7303 {$ESXMapping = “esx/3.5u4”}
    7302 {$ESXMapping = “esx/3.5u3”}
    default {$ESXMapping = “Unknown”}
    }

    $row = New-Object -Type PSObject -Property @{
    Name = $VMInfo.Name
    ToolsVersion = $VMInfo.ToolsVersion
    ESXMapping = $ESXMapping
    }
    $Report += $row
    return $Report

    }
    }

    To accomplish b), Simply copy and paste the above into your current PowerCLI window and hit enter twice at the end. If you now type Get-VM | Get-VMToolsMa and then press Tab, you should see it complete the function name for you to “Get-VM | Get-VMToolsMapped. Press Enter and the function should work. Shout if any of the above doesn’t make sense and I’ll help you out.

    Cheers,
    Sean

  3. Thanks for putting this together and making it public. Very useful.

    Except I’m not getting any results listed (My Get-VM statement is working but when I use Get-VM | c:\scripts\Get-VMToolsMapped.psi I don’t get any results listed — it just goes back to the prompt with nothing displayed. I’m using PowerCLI 5.0.1 and it’s trying to get the VMTools versions from VCenter 5.0 with ESXi 5.0 servers.

    Any ideas?

    Thanks for your help.

    Datto

Leave a Comment