Saturday, July 2, 2016

Force all VMs to check and update VMware tools at reboot

When I started my new job I noticed that most of the VMs were up to six versions behind in regards to VMware Tools.  I was having NIC stability issues and weird random lockups so I wanted to take a big swing at this issue.  I decided to google how to turn set the “ToolsUpgradePolicy” to "UpgradeAtPowerCycle".  Below is what I found and worked for me as is. For the record the VMware Tools upgrades did stabilize my VMs.

Start of script

connect-viserver -server "your server" -user “domain\user” -password “your password”

#Turn on auto update at next boot

Foreach ($v in (get-vm)) {
$vm = $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
$vm.ReconfigVM($vmConfigSpec)
}

Disconnect-VIserver * -confirm:$false

End of script

Also though it was good to figure out how to turn this off if all hell breaks loose. 
Here it is:

Start of script

connect-viserver -server "your server" -user “domain\user” -password “your password”

#turn off auto update at next boot

Foreach ($v in (get-vm)) {
$vm = $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = "manual"
$vm.ReconfigVM($vmConfigSpec)
}

Disconnect-VIserver * -confirm:$false

End of script

No comments:

Post a Comment