The other day I was looking at my virtual machines’ VMware Tools status, and sadly, many of them are out of date. It seems like I spend a lot of my time on host patching, but the Tools update seems to fall by the wayside. Perhaps it’s the disruption to production that rebooting causes (and the related change records and change management meetings), or maybe it’s the sheer number of VMs that I have to manage. I was curious what other folks’ infrastructure looked like, so I posed the question on Twitter: “#VMware admins, how good are you at keeping the Tools up to date?”
I only got a handful of responses, but they varied from “fanatical”, to “so so”. Tim Oudin said that he keeps his virtual machines up to date by setting “Check and upgrade Tools during power cycling” under a VM’s Options > VMware Tools. That got me thinking, “How can I enable that setting on hundreds of VMs?”
The answer is (of course) PowerCLI. Since there’s no cmdlet that will do this, we have to utilize our good friend, the vSphere API. The data object that we’re interested in is VirtualMachineConfigSpec. While doing the necessary research for this article, I ran into a very interesting property, changeVersion. This property is useful because it guards against updates that have happened between when the VM’s configInfo is read and when it is applied. We don’t need to increment or change the value of the changeVersion property, we just need to supply the current changeVersion.
Enabling VMware Tools upgrade at power cycle:
$vm = Get-VM -Name "virtualmachine" $spec = New-Object VMware.Vim.VirtualMachineConfigSpec $spec.changeVersion = $vm.ExtensionData.Config.ChangeVersion $spec.tools = New-Object VMware.Vim.ToolsConfigInfo $spec.tools.toolsUpgradePolicy = "upgradeAtPowerCycle" $_this = Get-View -Id $vm.Id $_this.ReconfigVM_Task($spec)
Enabling a VM to sync its time with the host:
$vm = Get-VM -Name "virtualmachine" $spec = New-Object VMware.Vim.VirtualMachineConfigSpec $spec.changeVersion = $vm.ExtensionData.Config.ChangeVersion $spec.tools = New-Object VMware.Vim.ToolsConfigInfo $spec.tools.syncTimeWithHost = $true $_this = Get-View -Id $vm.Id $_this.ReconfigVM_Task($spec)
Here are the snippets you’ll need in case you want to undo these settings.
Disabling VMware Tools upgrade:
$spec.tools.toolsUpgradePolicy = "manual"
Disabling VM time sync:
$spec.tools.syncTimeWithHost = $false