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

13 Replies to “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

  5. Hi Team,
    I need an out-put by using PoweCLi as following :
    1) Cluster hardware type
    2) ESXi version of cluster
    3) OS supported by cluster
    4) VDS type of cluster
    5) Over-provision of the cluster
    Anyone please help me.

    1. Great question. I really wish I was a team. The elements you asked for are a challenge:
      1) Hardware information is from the hardware provider -> vCenter only has the data exposed by your native hardware provider I have done some PowerCLI for HP before but have no idea on the other vendors – assuming you have the right drivers installed in ESX to get the information.
      2) Version can be done with Get-View -ViewType HostSystem -Property Name,Config.Product | Format-Table Name, @{L=’Host Version & Build Version’;E={$_.Config.Product.FullName}}
      3) This information is on VMware’s website and not available via API
      4) this can be done with get-virtual switch command
      5) I am not sure what you are asking here… are you asking for usage or allocation. I have seen a number of people do a virtual cpu to physical CPU ration or virtual memory to physical memory but I am not really sure what you are looking for here…

      Most of the stuff you want that is exposed is available in RV-Tools and I suspect it would better fit your needs than writing your own PowerCLI.

Leave a Reply to Matt Gore Cancel 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.