Powercli – How to get Vmware tools version

Classic problem keeping vmware tools up to date.   Here is a set of power shell scripts to help you figure out what machines have old tools and need updates.  I run a version of this script as an email sent to me once a week.

Q: How do I get a list of the Vmware tools on each virtual machine?

get-vm | % { get-view $_.id } | select Name, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}},@{ Name="ToolStatus"; Expression={$_.Guest.ToolsVersionStatus}}

Q: How do I get a list of the Vmware tools on each powered on virtual machine?

get-vm | where {$_.powerstate -ne "PoweredOff" } | % { get-view $_.id } | select Name, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}},@{ Name="ToolStatus"; Expression={$_.Guest.ToolsVersionStatus}}

Q: How do I get a list of the Vmware tools that are not up to date on each powered on virtual machine?

get-vm | where {$_.powerstate -ne "PoweredOff" } | where {$_.Guest.ToolsVersionStatus -ne "guestToolsCurrent"} | % { get-view $_.id } | select Name, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}}, @{ Name="ToolStatus"; Expression={$_.Guest.ToolsVersionStatus}}

Q: How do I get a list of the Vmware tools that are not up to date on each powered on virtual machine and output it to csv?

get-vm | where {$_.powerstate -ne "PoweredOff" } | where {$_.Guest.ToolsVersionStatus -ne "guestToolsCurrent"} | % { get-view $_.id } | select Name, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}}, @{ Name="ToolStatus"; Expression={$_.Guest.ToolsVersionStatus}} | Export-Csv -NoTypeInformation -UseCulture -Path C:\Temp\VMHWandToolsInfo.csv

11 thoughts on “Powercli – How to get Vmware tools version

  1. Nice info.

    The NotUpToDate and PoweredOn one is not acurate. ToolsVersionStatus is not valid, should be ToolStatus. This is 5.5.

    ‘where {$_.Guest.ToolStatus -ne “guestToolsCurrent”} ‘

    1. Evening,

      I think this will work sorta:

      New-VIProperty -Name GuestFullName -ObjectType VirtualMachine -ValueFromExtensionProperty ‘Guest.GuestFullName’ -Force
      New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine -ValueFromExtensionProperty ‘Guest.ToolsVersionStatus’ -Force
      New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine -ValueFromExtensionProperty ‘Config.tools.ToolsVersion’ -Force

      get-vm | where-object {$_.GuestFullName -like “*Linux*”} | select Name,GuestFullName,ToolsVersionStatus,ToolsVersion

      The issue is not all Linux OS’s use Linux … like CentOS.

      Enjoy

  2. Hi Joseph,

    had a little issue with your query here and I just wanted to give you feedback in case s.o. else is experiencing the same:

    actually the toolsVersionStatus field is not available so the query isn’t working like intended and I got VMs that were already up to date.

    my workaround was to insert a Get-View command a little earlier than mentioned above:

    Get-VM | where {$_.powerstate -ne “PoweredOff” } | Get-VIew | where {$_.Guest.ToolsVersionStatus -ne “guestToolsCurrent”} | select Name, @{ Name=”ToolsVersion”; Expression={$_.config.tools.toolsVersion}}, @{ Name=”ToolStatus”; Expression={$_.Guest.ToolsVersionStatus}}

    Please get back to me if I am wrong in here.

    Thx for sharing your knowledge w/ the community anyways.

    bye

  3. Hi Joseph,
    That is very useful stuff. Thanks. However it only displays the general tools version and not the exact build number. Would it be possible to get the exact build number of the tools for windows and for Linux guests?
    thanks again.

    1. Evening,

      Thanks for the comment. You have asked for the golden ticket. Lots of people have asked VMware for this. The simple answer is the build number in the first query is the only available information to vSphere. So you have to create a function to link them. Take a look at this script for logic : http://www.shogan.co.uk/vmware/figuring-out-what-build-of-esx-or-esxi-vmware-tools-maps-to-for-vms-using-powercli/ It’s the best I can offer.

      Thanks,
      Joseph

  4. I am using the following command:

    get-vm | where {$_.powerstate -ne “PoweredOff” } | where {$_.Guest.ToolsVersionStatus -ne “guestToolsCurrent”} | % { get-view $_.id } | select Name, @{ Name=”ToolsVersion”; Expression={$_.config.tools.toolsVersion}}, @{ Name=”ToolStatus”; Expression={$_.Guest.ToolsVersionStatus}}

    I would also like to return the OS of the VM and the host it resides on.. not having much luck..any ideas?

    1. Matt,

      Thanks for reading. This one is challenging due to the object. I am not sure I could do this in a one liner. I would suggest a for loop for example

      $vms = get-vm

      foreach ($vm in $vms)
      {
      $info = get-vm $vm | where {$_.powerstate -ne “PoweredOff” } | where {$_.Guest.ToolsVersionStatus -ne “guestToolsCurrent”} | % { get-view $_.id } | select Name, @{ Name=”ToolsVersion”; Expression={$_.config.tools.toolsVersion}}, @{ Name=”ToolStatus”; Expression={$_.Guest.ToolsVersionStatus}}

      }

      Then looping the information into an array for storage outside the loop… then export to csv Let me know if you have additional questions

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.