Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

PowerCLI Get-VMToolsVersion

Posted on April 9, 2010

I recently was able to upgrade my VMware server so that I can now fully use the PowerCLI tool set. This is fantastic PowerShell goodness that I hope to use and write about much more in the future. Part of my upgrade process includes upgrading the VMToools install on the virtual machines. But what wasn’t so easy is to pull out the tools version currently installed. The information is there when using Get-View, but it takes a little bit of work. So naturally I developed my own solution.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

I wrote a PowerShell 2.0 function that can work in a pipelined expression to return the tools version number.

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

The function takes a virtual machine object as a parameter and uses Get-View to retrieve the ToolsVersion property. I could have created a new custom object, but I decided to simply add this as a new property to the virtual machine object using Add-Member. Using –passthru means the object is written back to the pipeline. Because the default formatter doesn’t recognize this property, you have to explicitly ask for it. But that’s pretty easy and as you can see very helpful.

[vSphere PowerCLI] C:\Scripts> get-vm | get-vmtoolsversion | sort ToolsVersion |

format-table name,toolsversion -autosize

Name                                 ToolsVersion

----                                 ------------

Win2K8R2 Baseline                            7303

Win7 Baseline                                7303

MyCompany Exchange 2007                      8193

MyCompany Vista                              8193

ResearchDC                                   8193

Research Member Server R2                    8193

MyCompany Windows 7                          8193

R2 Core RODC                                 8193

R2 Server Core Baseline                      8193

MyCompany 2008                               8193

MyCompany XP                                 8194

MyCompanyDC 2K3R2                            8194

MyCompany XP Restored                        8194

MyCompany2003                                8194

The function includes comment based help, but is lacking any sort of robust error handling. I suppose I should add that in.

I’m still learning all the ins and outs of PowerCLI but this meets my needs and maybe it will meet yours.


Behind the PowerShell Pipeline
Download get-vmtoolsversion.ps1

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d