The greatest challenge to any thinker is stating the problem in a way that will allow a solution

Bertrand Russell


On 2 Mar 2012

PowerCLI, VMware

Tags: ,

Upgrading VMTools always seems like such an afterthought.  You get through the effort of upgrading your vCentre, and ESX’s without any service interruption, then are left with a load of VM’s with out-of-date Tools and little authority to take them down as part of the upgrade.  Plus if you’re faced with the drudgery of having to speak to all sorts of different people and departments, its the kind of task that is only ever on the back-burner.

I tend to try to upgrade machines during ad-hoc reboots, which isn’t always sensible (during an service incident for example), and requires you to remember (not always possible if you’ve been up most of the night due to young kids / over exuberant drinkage).

There is an often overlooked option that lets you automatically update VM’s during a bounce, the only problem is – how to set on all your VM’s and retain full use of your mouse wielding arm and eyes…?The option can set via the Advanced settings of an individual VM (note that in VI3, the option is greyed out whilst VM’s are powered on, but the setting can be changed on the fly using the script below).

VM Advanced Options

Here's the option we want to set


What does it do?

When your VM is shutting down, and if there’s a VM Tools update available, it will upgrade (at much the same time that OS updates would be automatically applied if Windows Update is set to update).  It does delay OS shutdown, and causes a little pop-up window to be displayed.  In most environments this will be fine, though in locked down production environments you’ll probably have to stick with the old-fashioned manual way.

VM Tools Auto Upgrade

This is what it looks like when the setting takes effect on OS shutdown


Note that its worth converting your VM Templates into VM’s prior to running the script, that way any future deployments will also have the option set.  If you’ve got lots of templates, you can convert them to VM’s using the script found on this post at TechDump.

The Script

The below script will apply to all VM managed by the vCentre(s) your PowerCLI session is currently logged into, if you want to restrict to VM’s in a cluster or folder or vApp, use one of the commented out lines

UPDATE:  Added a check to see if a VM’s ReconfigVM method has been disabled, if so you can’t change anything so there’s no pint trying

$UpgradePolicy = "upgradeAtPowerCycle"      # Other option: manual
Write-Host "Setting all VM Tool's upgrade policy to $UpgradePolicy"
Write-Host "Get list of VMs to check/update..."
$vms = Get-VM
# $vms = Get-VM -Location (Get-Cluster -Name "Cluster Name")
# $vms = Get-VM -Location (Get-Folder -Name "Folder Name")
# $vms = Get-VM -Location (Get-VApp -Name "vApp Name")
Write-Host (" " + $vms.count + " VMs")
# Create config spec to apply
$VMcfgSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$VMcfgSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$VMcfgSpec.Tools.toolsUpgradePolicy = "upgradeAtPowerCycle"
$count = 0
foreach ($vm in $vms) {
    $count ++
    Write-Progress -Activity "Checking/applying 'upgradeAtPowerCycle' setting to VMs" -Status ("Doing " + $vm.Name) -PercentComplete ($count/($vms.count)*100)
    # Check current settings
    $vmView = Get-View $vm -Property DisabledMethod, Config.Tools.ToolsUpgradePolicy
    # Can't change if ReconfigVM is disabled on VM, so skip
    if ($vmView.DisabledMethod -contains "ReconfigVM_Task") {
    # Change if required
    if ($vmview.Config.Tools.ToolsUpgradePolicy -ne $UpgradePolicy) {
Write-Host "Job done!"

The above script was inspired, and made possible by a post I came across on Damian Karlson’s blog, take a look for yourself.  I’ve just added some text output and progress display, the meat of the script is lifted directly from his site, plus there’s some useful comments under the post.

Leave a Reply

XHTML: You can use these tags if you know what they are: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.