#requires -version 2.0 #Jeffery Hicks #http://jdhitsolutions.com/blog #Learn more PowerShell: #Windows Powershell 2.0: TFM by Don Jones & Jeffery Hicks (SAPIEN Press 2010) Function Get-VMToolsVersion { #requires -pssnapin VMWare.VimAutomation.Core <# .Synopsis Get VMware Tools version for a given virtual machine. .Description This function will add the ToolsVersion property to a virtual machine object. The object is written to the pipeline but because the default formatted view doesn't know about the property you need to use Select-Object to display it. .Parameter VM A virtual machine object. .Example PS C:\> get-vmtoolsversion (get-vm researchdc) | select ToolsVersion Get the ToolsVersion for the ResearchDC virtual machine .Example PS C:\> get-vm | get-vmtoolsversion | Sort ToolsVersion | select Name,ToolsVersion, PowerState Presents a summary report of all virtual machines displaying the virtual machine name, the version of VMware Tools, and its power state. .Example PS C:\> get-vm | get-vmtoolsversion | where {$_.ToolsVersion -lt 8194} | sort ToolsVersion | select Name,ToolsVersion,PowerState Similar to the previous example except it returns only VMs with tools version less than 8194. Output is sorted by the version. .Inputs Virtual Machine object .Outputs A customized Virtual Machine object .Link Get-VM Get-View .Notes NAME: Get-VMToolsVersion VERSION: 1.0 AUTHOR: Jeffery Hicks LASTEDIT: 4/8/2010 #> [cmdletbinding()] Param ( [Parameter(Position=0, Mandatory=$True, ValueFromPipeline=$True, HelpMessage="You must specify a virtual machine object")] [VMWare.VimAutomation.Client20.VirtualMachineImpl[]]$vm ) Begin { Write-Verbose "Starting function" } Process { Write-Verbose "Getting view for $($vm.name)" $view=Get-View -viObject $vm $ToolsVersion=$view.Config.Tools.ToolsVersion write-verbose "Found tools version value of $ToolsVersion" $vm | Add-Member -MemberType NoteProperty -Name "ToolsVersion" -Value $toolsVersion -passthru } End { Write-Verbose "Ending function" } } #end Function #help Get-VMToolsVersion -full