VMware Cloud Community
pfuhli
Enthusiast
Enthusiast
Jump to solution

How to get VMware Tools version info?

Hi there,

is it possible to query for the VMware Tools version info of a VM?

Is there an object/property reference anywhere? I don't know how to query for properties of objects the cmdlets are returning.

Thanks for your help!!

Regards,

daniel

0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

ok, I found that already - but how do I know that it is "config.tools.toolsVersion"?

sorry for my awkwardness Smiley Wink

Well, let's say that it sort of an... adventure.

Let's start from the VirtualMachine. We know that the tools version must be hiding in here somewhere, so we scroll down to the properties list. The second property, config, looks fairly promising, so we click on its data type, which happens to be VirtualMachineConfigInfo. If we look at its property list, toward the bottom, we see a property called tools, which is of type ToolsConfigInfo. Examining this object we finally find what we're looking for, the toolsVersion integer within the ToolsConfigInfo object.

This is how I determined the right thing to use was config.tools.toolsVersion, the name of the property I wanted in VirtualMachine was config, the name of the property in VirtualMachineConfigInfo was tools and the property I wanted was toolsVersion. Joining the names together with ., as I would if I were accessing a nested object in Java/C# or other languages causes the data I want to be returned. When I do this I arrive at the string config.tools.toolsVersion. You could think of this as a top-down approach to finding where the data you want lives in the API.

Often you don't know exactly where to look for the information you want. In this case we can adopt a bottom-up approach. What you can do in this case is use the search interface of the top-level API document. If you click on "All Types" there and type in "tools", you'll find the ToolsConfigInfo data object. Since ToolsConfigInfo is a data object, rather than a managed object, you won't be able to query for it directly. Instead you have to look for a managed object that contains this data object. At the top of a data object's API page there is a section called "Property Of", which lists the objects that contain this information. In the case of ToolsConfigInfo this is VirtualMachineConfigInfo and VirtualMachineConfigSpec. One tip to keep in mind when doing this, Info objects contain persistent information about objects whereas Spec objects are used to change the configuration of objects. In other words, we don't have to bother looking at the VirtualMachineConfigSpec object when we're trying the path to use to query the data we want. When we look at the VirtualMachineConfigInfo object we see that it, in turn, is a property of a VirtualMachine object, which is the kind of object we get back from get-vm. We still have to refer to the properties list to determine what the objects are called, but the end result is the same, config.tools.toolsVersion.

I hope that helps. We realize this is pretty tricky, which is one of the reason we're developing the PowerShell toolkit in the first place. In total a VM has over 1000 properties and finding the one you want can be a challenge, which is why we're trying to put the most valuable stuff in the objects you get back from cmdlets like get-vm.

View solution in original post

0 Kudos
11 Replies
admin
Immortal
Immortal
Jump to solution

Currently this requires using the get-view cmdlet to access the full object. Here's a script that will do it:

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

Here's some sample output below. 0 means that Tools is not installed.

Name ToolsVersion

- - - - - - - - -

Lifecycle Manager 0

ESX 3.5 0

Snapshot VM 0

ESX 3i 0

Nostalgia 0

Harvey's empty VM 0

ManagementVM_as_of_12-28-07 0

Windows 2003 64 UI 0

Windows 2000 UI 0

testme 0

Windows 2003 PS 0

Windows 2003 UI 0

Windows 2000 PS 0

Windows 2003 64 PS 0

SDK-MAIL02 0

SDK-MAIL01 67370

pfuhli
Enthusiast
Enthusiast
Jump to solution

That works perfect. Thanks.

But where can I find information about all the objects and properties in general?

0 Kudos
admin
Immortal
Immortal
Jump to solution

That works perfect. Thanks.

But where can I find information about all the objects and properties in general?

For that you can refer to the SDK API Documentation.

For example, the information I got the information on Tools from the ToolsConfigInfo object.

pfuhli
Enthusiast
Enthusiast
Jump to solution

ok, I found that already - but how do I know that it is "config.tools.toolsVersion"?

sorry for my awkwardness Smiley Wink

0 Kudos
admin
Immortal
Immortal
Jump to solution

ok, I found that already - but how do I know that it is "config.tools.toolsVersion"?

sorry for my awkwardness Smiley Wink

Well, let's say that it sort of an... adventure.

Let's start from the VirtualMachine. We know that the tools version must be hiding in here somewhere, so we scroll down to the properties list. The second property, config, looks fairly promising, so we click on its data type, which happens to be VirtualMachineConfigInfo. If we look at its property list, toward the bottom, we see a property called tools, which is of type ToolsConfigInfo. Examining this object we finally find what we're looking for, the toolsVersion integer within the ToolsConfigInfo object.

This is how I determined the right thing to use was config.tools.toolsVersion, the name of the property I wanted in VirtualMachine was config, the name of the property in VirtualMachineConfigInfo was tools and the property I wanted was toolsVersion. Joining the names together with ., as I would if I were accessing a nested object in Java/C# or other languages causes the data I want to be returned. When I do this I arrive at the string config.tools.toolsVersion. You could think of this as a top-down approach to finding where the data you want lives in the API.

Often you don't know exactly where to look for the information you want. In this case we can adopt a bottom-up approach. What you can do in this case is use the search interface of the top-level API document. If you click on "All Types" there and type in "tools", you'll find the ToolsConfigInfo data object. Since ToolsConfigInfo is a data object, rather than a managed object, you won't be able to query for it directly. Instead you have to look for a managed object that contains this data object. At the top of a data object's API page there is a section called "Property Of", which lists the objects that contain this information. In the case of ToolsConfigInfo this is VirtualMachineConfigInfo and VirtualMachineConfigSpec. One tip to keep in mind when doing this, Info objects contain persistent information about objects whereas Spec objects are used to change the configuration of objects. In other words, we don't have to bother looking at the VirtualMachineConfigSpec object when we're trying the path to use to query the data we want. When we look at the VirtualMachineConfigInfo object we see that it, in turn, is a property of a VirtualMachine object, which is the kind of object we get back from get-vm. We still have to refer to the properties list to determine what the objects are called, but the end result is the same, config.tools.toolsVersion.

I hope that helps. We realize this is pretty tricky, which is one of the reason we're developing the PowerShell toolkit in the first place. In total a VM has over 1000 properties and finding the one you want can be a challenge, which is why we're trying to put the most valuable stuff in the objects you get back from cmdlets like get-vm.

0 Kudos
pfuhli
Enthusiast
Enthusiast
Jump to solution

Dear Carter,

that's a pretty good explanation - I think I got it now Smiley Happy

Thanks for being so patient!

daniel

0 Kudos
angoletti1
Contributor
Contributor
Jump to solution

Hi,

if I use this command, it starts to show the output in 2 colums (Name, ToolsVersion) but I can't see anything. It looks like a empty list.

Any ideas?

0 Kudos
admin
Immortal
Immortal
Jump to solution

Hi,

if I use this command, it starts to show the output in 2 colums (Name, ToolsVersion) but I can't see anything. It looks like a empty list.

Any ideas?

Could you try this script:

get-vm | % { get-view $_.ID } | fl *

and see if you get any output?

0 Kudos
angoletti1
Contributor
Contributor
Jump to solution

In the attachment you can find the output.

0 Kudos
aw443
Contributor
Contributor
Jump to solution

I realize this post is a little old but I found it interesting, and used it for reference in putting together something that returns the VM display name, its host name, tools status, and toolsversion. It then sorts by the name and outputs to a csv file, and appends the filename by the date and time.

I use this to generate a weekly report for a VMware tools upgrade project my team is working on. With all the VM's we have in our environment, and the amount of bru-ha-ha we have to go through to make a single change (I'm sure we all love-hate change control), this project will take a while to complete. Until then, I will be running this weekly. I've received requests to "make the report prettier". Granted this is just an output. I can paste into xls and add colors and formatting to make it easier to look at, but I'm wondering if there is anyway to just improve upon the csv output within the code itself so it comes out a little cleaner, or "prettier". Any ideas?

I understand it may not be as nice as presenting it into a wonderfully formatted xls spreadsheet, but i'm hoping it may create an easier output to digest for the reader, and save me some time on the xls front.

All in all this thread was very helpful to me in getting what I needed. Even if we can't pretty-it-up, its been helpful -- so I hope someone else can use this as well. Add or modify the expression and properties to suit what you need. Refer to the VI SDK here to view properties of the VM to call.

$date=get-date -uformat "%Y%m%d-%H%M%S"; get-vm | % { get-view $_.ID } | select Name, @{ Name="hostName"; Expression={$_.guest.hostName}}, @{ Name="ToolsStatus"; Expression={$_.guest.toolsstatus}}, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}} | sort-object name | export-csv c:\bin\out\vmtoolsver_$date.csv

-adubya

0 Kudos
R0v3r
Contributor
Contributor
Jump to solution

BRILLIANT!! Thank you SOO much for explaining it like this. So it is a hierarchical naming structure separated by "."

I have never been able to understand this stuff till this explanation.

0 Kudos