Change “Upgrade at Power Cycle” to enable automatic VMTools upgrades

VM Maintenance is a chore for most IT shops, but there are ways to make things easier! If your policies allow, you can set all VMs to upgrade VMTools on reboot. Since we usually reboot most VMs on a weekly or monthly basis, this makes it easy to allow the Tools to update whenever there is an ESXi update. This script will set the flag for all VMs in a datacenter, so keep that in mind.

<#
Title: 		Sets the Tools Upgrade Policy to "Upgrade at Power Cycle"
Author: 	Michael Kenning (mjkenning@gmail.com)
Version: 	0.2 (beta)
Usage: 		
Created:	08 SEP 2015
Updated: 	09 SEP 2015
NOTE:		
#>

### VARIABLES ###
$cluster = 'CLUSTERNAME'
$vcserver = "VCNAME"
### END VARIABLES ###

Connect-VIserver $vcserver

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec 
$spec.tools = New-Object VMware.Vim.ToolsConfigInfo 
$spec.tools.toolsUpgradePolicy = "upgradeAtPowerCycle"
Foreach($vmview in get-view -ViewType virtualmachine -SearchRoot (get-Cluster $cluster).id -Filter @{'Config.Tools.ToolsUpgradePolicy' = 'manual' } ) {
	$vmview.ReconfigVM_task($spec)
}
Advertisements
Tagged with: ,
Posted in PowerCLI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: