Skip to Content

The value of digging through an SDK

SDKs are really for programmers but have value for scriptor writers as well. A while ago I found a script to returns the version of VMware tools on guest systems (I didn't write it and wish I'd kept the source link but it does what I needed).

$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 vmtoolsver_$date.csv

Recently my co-worker did some upgrades to our clusters and ran the script and noted that a large portion of our VMware Tools were behind a version or two. He noted that several of our guest systems did not have the option checked in Edit Settings > Options > VMware Tools Check and upgrade Tools before each power-on' so he sent an email for people to manually check at the next opportunity. I figured there must be a PowerShell script way.

The above code gives me version info which is a start. A little searching gave me the VMware SDK which is on the VMware site. Looking at the script I see guest.toolsstatus and config.tools.toolsVersion that give me hope for a starting point. Let's shorten the script to it's basics and run a get-member on it.

get-vm SERVER01 | % { get-view $_.ID } | get-member

Looking at the results I see guest and config are property types. So I select All Properties and do a search for guest and config. Note much that looks interesting there. So I move to a search for tools and that gets me a link to toolsConfiguInfo. Selecting that gets me to a page with toolsUpgradePolicy which sounds like a winner. So for a test we try...

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

This gives us just what we need. To put it all together for the environment.
Get-VM | % {Get-View $_.ID} | select name, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}}, @{ Name="toolsUpgradePolicy"; Expression={$_.config.tools.toolsUpgradePolicy}} | sort Name

Now we send the email out for the various engineers to change their settings the next time they shut the systems down.

I realize that this is probably not the most efficient way to get the information but hopefully someone else will benefit learing how to dig through SDKs. When I was first introduced to SDKs they were very intimidating but a wealth of information. If you have a better way do please leave a comment.

Comments

Hey sepeck, not sure if I'd

Hey sepeck, not sure if I'd seen your blog before, glad to have found it. This thread talks about how to set the policy to upgrade at reboot: http://communities.vmware.com/message/935702

That thread so rocks. Not

That thread so rocks. Not sure how I missed it in my earlier searches. Currently you cannot set this flag on guest systems that are on through the GUI. The script enables you to set it with the system on. You rock Hal! My team has less work they have to do on our next patch window.

Code used from the thread....

get-viserver -server SERVERNAME
<code>
#    NAME: set-VMautoUpdate.ps1
#  AUTHOR: angoletti1 / LucD
#  SOURCE:  http://communities.vmware.com/message/937094#937094

[Reflection.Assembly]::LoadWithPartialName("vmware.vim")

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"

Get-VM | % { (Get-View $_.ID).ReconfigVM($vmConfigSpec)}