Managing VMware Tools advanced options in PowerShell

Here is a quick way of selecting the VMware Tools Advanced option: “Check and upgrade Tools during power cycling” for all VMs in a cluster. Here is a screen shot of the option in question:


And here is the script:

$vms = get-cluster "Cluster Name" | get-vm

foreach($vm in $vms) 
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.changeVersion = $vm.ExtensionData.Config.ChangeVersion
$ = New-Object VMware.Vim.ToolsConfigInfo
$ = "upgradeAtPowerCycle"
$_this = Get-View -Id $vm.Id