I was looking for a way to enable “Check and upgrade Tools during power cycling” for more than one VM at a time, but without enabling for all VM’s in the cluster.
In this case our naming convention allowed for the quick and simple use of wildcards to make selections.
From our test lab, I wanted to target only VM’s with “cel” in the name.
First, verify the targeted VM’s are all set to manual.
#check policy status Get-VM *cel* | sort name | Select Name,@{N="UpgradePolicy";E={$_.Extensiondata.Config.Tools.toolsUpgradePolicy}} Name UpgradePolicy ---- ------------- NAVCEL01 manual WEBCEL01 manual WEBCEL02 manual DEVCEL01 manual DEVCEL02 manual DEVCEL03 manual
Next, update the policy (effectively checking the box)
[cc lang=”powershell”]
#change the UpgradePolicy to upgradeAtPowerCycle
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = “UpgradeAtPowerCycle”
Get-VM *cel* | %{
$_.Extensiondata.ReconfigVM($vmConfigSpec)
}
[/cc]
Now to verify the targeted VM’s are all set to upgradeAtPowerCycle
#check policy status Get-VM *cel* | sort name | Select Name,@{N="UpgradePolicy";E={$_.Extensiondata.Config.Tools.toolsUpgradePolicy}} Name UpgradePolicy ---- ------------- NAVCEL01 upgradeAtPowerCycle WEBCEL01 upgradeAtPowerCycle WEBCEL02 upgradeAtPowerCycle DEVCEL01 upgradeAtPowerCycle DEVCEL02 upgradeAtPowerCycle DEVCEL03 upgradeAtPowerCycle
In the link below, you’ll find code to update all VM’s in a cluster.
Sources/Credits: Community member LucD at communities.vmware.com/message/1601811