Keeping VMware Tools up to date can be somewhat challenging as up until vSphere 5.1 installing updated version of VMware Tools requires a guest OS reboot which in many cases is not possible during normal operation hours. There is a simple solution though, in Virtual Machine settings on options tab and in VMware Tools settings there is a checkbox “Check and upgrade Tools during power cycling”
What this setting does, is that in case VMware Tools are out of date, and there are updated version available on ESXi host, VM will perform automatic VMware Tools update during any guest OS shutdown or startup event. I have used this feature with Windows VMs for years and it has proven to be reliable and very useful. With Linux VMs I would still go with manual VMware Tools update process, although automatic update of VMware Tools is supported on Red Hat Linux VMs.
So this is very handy feature, but this setting is not set by default, and going through all VMs in your infrastructure can be quite tedious task if done manually. Instead of clicking through all your VMs you can use an pretty simple vCenter Orchestrator workflow to configure all your Windows VMs for this.
With vSphere 5.1 vCenter Orchestrator (vCO) is configured automatically so I won’t go through all steps required for manual vCO configuration. If your vCO installation is not set up, please go through “Installing and Configuring VMware vCenter Orchestrator” document, you can get vCO up and running in no time with vSphere 5.1. Or you can leave a comment below and I will try to assist.
vCenter Orchestrator workflow
I have created a simple vCO workflow to set VMware Tools update policy to automatic for all Windows VMs in a vSphere cluster. Workflow has following steps:
- Get list of all VMs of a vCenter Server cluster object
- Loop through all VMs
- Check the guest OS id returned by VM object, if Windows check VMware Tools upgrade policy
- If Tools update policy is automatic already, skip to a next VM
- If Tools update policy is manual, reconfigure VM with automatic VMware Tools upgrade policy
Schema of workflow looks like this, click the image below to see it in greater detail
JavaScript used in the workflow
vCenter Orchestrator uses JavaScript as its scripting language. Usually you just need to write simple logic code which does not require much of learning if you already know any other scripting language like Perl, Python or PowerShell. I am no programmer by any means and I was able to pick necessary skills for JavaScript in few days.
More complex code like vSphere API calls can be generated automatically with help of VMware Fling Onyx. For example I used Onyx to create API call code for “Set VM Tools Update” script block in this workflow. Onyx is available at http://labs.vmware.com/flings/onyx.
Here are key parts of JavaScript code used in this workflow so you get an idea how Orchestrator scripting looks like.

Custom decision object “Need to set?” script to check guest OS type and Tools upgrade policy
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// store VM guest OS type in guestOs variable var guestOs = curVM.summary.guest.guestId; // initialize isWindows variable and match guestOs against "windows" keyword var isWindows = null; if (guestOs != null) { isWindows = guestOs.match(/windows/); } // check if isWindows is set if (isWindows) { // System.debug("VM guestOs is Windows"); if (curVM.config.tools.toolsUpgradePolicy == "upgradeAtPowerCycle") { // upgradeAtPowerCycle policy already set, no need to reconfigure System.debug("upgradeAtPowerCycle already set, skipping this VM"); return false; } else { // upgradeAtPowerCycle policy not set System.debug("upgradeAtPowerCycle is not set, continuing to reconfigure"); return true; } } else { // System.debug("VM guestOs is not Windows"); return false; } |
curVM is a VM object picked up from array of all VMs in a cluster. In that VM object you have all properties of a VM, including guest OS type.
By matching guest OS type to a keyword “windows” we are able to figure out if VM we are processing is a Windows VM or not. If guest OS type is Windows then we check its VMware Tools upgrade policy to avoid unnecessary reconfiguration operations. If VMware Tools update policy is not “upgradeAtPowerCycle” we will exit this Custom description type workflow object with return code “true” which will lead to “Set VM Tool Update” workflow object.

“Set VM Tools Update” script object code
|
1 2 3 4 5 6 7 8 9 10 11 12 |
// Following code block is generated using Onyx var spec = new VcVirtualMachineConfigSpec(); spec.tools = new VcToolsConfigInfo(); spec.tools.toolsUpgradePolicy = "upgradeAtPowerCycle"; // Sleep 1 second before each reconfigure task to avoid stressing vCenter Server too much System.sleep(1000); // Execute reconfig task using specification stored in spec curVM.reconfigVM_Task(spec); System.debug("Set upgradeAtPowerCycle for " + curVM.name); |
In this workflow object we have a code which will set VMware Tools update policy of a current VM to “upgradeAtPowerCycle”. Before we apply this configuration script will sleep for a one second to avoid sending configuration tasks to a vCenter Server with too high rate.
These are two most complex JavaScript code blocks used in this simple workflow.
How to import workflow
To install this workflow download it from a link at the end of this article. Once you have downloaded workflow file open vCO client, login to vCO server and in client select workflows tab as shown on image below
First you need to decide where to import workflow. You can either create a new folder for imported workflows by right clicking at the top most menu item and selecting “Add folder…”, or you could import workflow to a existing folder, like “Library”.
Now right click desired folder and select “Import workflow…” and browse workflow you downloaded. Once done should have “Enable VM Tools upgrade on VM power cycle” workflow added into your workflow inventory.
How to execute workflows
With release of vSphere 5.1 accessibility of vCO workflows has improved a lot. Before vSphere 5.1 you had either to use vCO client or some custom interface to run workflows, in vSphere 5.1 ability to execute vCO workflows is integrated in new vSphere Web Client!
You can execute workflow from vCO client by right clicking a workflow and selecting “Start workflow…” or you can just select it and press CTRL+R. vCO client will then open a dialog window to ask necessary input parameters for a workflow. In case of workflow show here you need to select vCenter Server cluster object in which you wish to execute this workflow. To get list of cluster objects click “Not set” link and press enter in “Filter:” input box, vCO client will then search for all cluster objects and list them for you to choose.
Alternatively you can associate this workflow to a cluster object in vSphere Web Client for easy access.
Login to vSphere Web Client with administrator privileges, and click “vCenter Orchestrator” link on the left side menu.
In next view you should see “vCO Servers: 1” on left side menu if your vCO is properly registered with VMware SSO and Web Client services. Integration is configured automatically when doing vCenter Server Simple install.
If you have vCO registered select “Manage” tab, and click green plus sign to add a new workflow association.![]()
Next browse workflow from the tree menu on the left side, click “Add” and select “Cluster” from available type list.
Now you have associated this workflow with vSphere cluster object, to run workflow go and right click any cluster in Web Client and select workflow from “All vCenter Orchestrator Actions” menu. Any changes made by workflow are listed in Cluster –> Monitor –> Tasks view.
Workflow download
Feel free to download this workflow from link below, you may use, distribute and modify it as you wish. I will not provide any guarantee that this workflow will work as intended in your environment.
http://v-reality.info/files/EnableVMToolsUpgradeOnVMPowerCycle.workflow
Or use PowerCLI:
get-cluster CLUSTER_NAME_HERE | get-vm VM_NAME_HERE_OR_REMOVE_FOR_ALL_VMS | where-object {
$_.guest.OSFullname -match “^Microsoft Windows*.”
} | foreach-object {
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = “UpgradeAtPowerCycle”
(Get-View $_.ID).ReconfigVM($vmConfigSpec)
}
It is true that same can be achieved using PowerCLI. Point of this blog post is however to show capabilities of vCenter Orchestrator for people new to it.