PowerShell Script to enable the "Check and upgrade Tools before each power-on" option.


Summary:
With this powershell script, you can enable the "Check and upgrade Tools before each power-on" option on all your VM's without having to power them off.
$ErrorActionPreference = "SilentlyContinue"
connect-viserver -server [VCServer or ESX Host] -user [user] -password [password]
get-vm | foreach-object {
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
(Get-View $_.ID).ReconfigVM($vmConfigSpec)
}
Configuration:
Virtual Center 2.5 Build 104215
ESX Server 3.5 Update 2 (110268)
PowerShell V1 using PowerGUI 1.5.2.550 w/ VI Toolkit 1.0 Update 1 Build 113525

Caveats:
  1. [UPDATE: The script has been updated to continue past any errors generated. So if any VM's have issues it will just continue to the next VM in line to update. You will have to audit systems that were not updated with the script and fix them manually.]
  2. This script does not have error handling, so if a VM is in the midst of another task, the script will fail with following error:
    • Exception calling "ReconfigVM" with "1" argument(s): "Operation failed since another task is in progress."
    • All systems up to the error will have been updated.
  3. To test this script against one or two machines only simply change line 2 to the following:
    • get-vm [VMGuestSystemName] | for-eachobject {

2 comments:

gcballard said...

Thanks man. worked like a charm!

Anonymous said...

Thanks! Works with vCenter 5.5.