Home Datacenter Automating VMware Tools upgrades on VM reboot with PowerCLI

Automating VMware Tools upgrades on VM reboot with PowerCLI

by Philip Sellers

When it comes to improving the health of an existing vSphere environment, one of the first lifts that you should try is upgrading all of the VMware Tools to the current version of your ESXi hosts.  A lot of times, the VMware Tools get installed during initial deployment and forgotten.  VMware has made a lot of progress in the capabilities packaged in VMware Tools.  These capabilities appears to be accelerating with some new developments like AppDefence.

VMware offers a few ways to upgrade the tools, but one of the methods with least impact is the upgrade on reboot.  Officially, Upgrade on Power Cycle was introduced back with vSphere 5.1, but a lot of folks have overlooked this checkbox in the VM configuration.

Step 1

Set your templates!  May sound crazy, but lets fix the future before addressing the past.  Go into your templates and set the Upgrade on Power Cycle setting inside of the VM configuration.   Right click your template, choose Edit Settings and then go to the VM Options tab (in either the vSphere Client or the HTML5 Client).  Check the box for “Check and upgrade VMware Tools before each power on” button and click OK to save the setting.

Step 2

Fix the past!  The PowerCLI below will create an object and then embed another object inside and set its value to “UpgradeAtPowerCycle.”  The same config object can be used to reconfigure every VM in your environment to set this setting.

[code language=”PowerShell”]# VMware Tools Automatic Upgrade on PowerCycle

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
Get-VM | Where {$_.ExtensionData.Config.Tools.ToolsUpgradePolicy -like "manual"} | ForEach { $_.ExtensionData.ReconfigVM_task($vmConfigSpec) }[/code]

You may also like