Wednesday, June 19, 2013

Automatically Check and Upgrade VMware Tools During Power Cycling

After upgrading a cluster of ESXi 5.0 hosts to ESXi 5.1U1, I was once again nagged by the menial tasks of upgrading VMware tools and the VM hardware. Fortunately, there is a setting that you can configure within each VM to automatically check and upgrade VMware tools during a power cycle. This setting can be found under the "options" tab in the Virtual Machine settings:



As an added bonus, this can be scripted to change the setting for all VMs using PowerCLI (thanks to this blog).

Connect-VIServer -Server vcenter

Get-Cluster -Name "Cluster-Name" | Get-VM | Get-View | ForEach-Object{

if ($_.config.tools.toolsUpgradePolicy -ne “upgradeAtPowerCycle”){

$vm = Get-VM -Name $_.name
$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)

}
}

Disconnect-VIServer vcenter

No comments:

Post a Comment