Keeping VM Tools up to date is like painting the Forth Bridge (an endless task which, just as you finish, another ESX release goes live and you start all over again). A useful, but almost hidden feature, is that which allows VM’s to automatically update when they’re being bounced. Meaning that some VM’s will be upgraded when machines are being otherwise rebooted.
The following script, applies the setting to all VM’s managed by a vCentre, but you can edit the Get-VM line to select the VM’s you want to change. Note that you might want to disable the feature, in which case change $UpgradePolicy = “manual” .
Despite the Check and upgrade Tools before each power on option being greyed out for powered on VM’s in VI3, this script will still change the setting. Which is nice.
$UpgradePolicy = "upgradeAtPowerCycle" # Other option: manual
Write-Host "Setting all VM Tool's upgrade policy to $UpgradePolicy"
Write-Host "Get list of VMs to update..."
$vms = Get-VM
Write-Host ("...got " + $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"
# Go through all the VM's and update
$count = 0
foreach ($vm in $vms) {
$count ++
Write-Progress -Activity "Applying 'upgradeAtPowerCycle' setting to VMs" -Status ("Updating " + $vm.Name) -PercentComplete ($count/($vms.count)*100)
# Get current setting
$vmView = Get-View $vm -Property Config.Tools.ToolsUpgradePolicy
# Change if setting isn't as we want
if ($vmview.Config.Tools.ToolsUpgradePolicy -ne $UpgradePolicy) {
$vmView.ReconfigVM($VMcfgSpec)
}
}
Write-Host "Job done!"
Hi there,
Great script.
However you define $UpgradePolicy = “upgradeAtPowerCycle” at start, but at $VMcfgSpec you hardcode the value instead of using your variable.
Same goes for the progress message
Regards,