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.