Set-UpdateToolsPolicy–For your VM’s

In continuation to William Lam’s post on how you can Automating VMware Tools Upgrade Policy and thanks to a comment left on the post – I wanted to perform the same functionality in PowerCLI.

I present to you the Set-UpdateToolsPolicy Function

Function Set-UpdateToolsPolicy {
			A function to change the update policy one or more VM's 
			This script will change the VMware Tools Update policy 
			on one or many virtual machines
			The name of one or more virtual machines, this can be 
			passed from the pipeline
		.PARAMETER  Policy
			The policy setting - has to be be either manual (do not try 
			and upgrade tools on each boot cycle) or upgradeAtPowerCycle 
			(tools will be checked for upgrade at each power cycle)
			PS C:\> Get-VM foo | Set-UpdateToolsPolicy -Policy manual
			PS C:\> Set-UpdateToolsPolicy -VM foo -Policy upgradeAtPowerCycle
			Author: Maish Saidel-Keesing


	begin {
	$config = New-Object VMware.Vim.VirtualMachineConfigSpec
	$config.Tools = New-Object VMware.Vim.ToolsConfigInfo
	$config.Tools.ToolsUpgradePolicy = $Policy
        foreach ($vmobject in (Get-VM $VM)) {
Line 31: Using [ValidateSet("manual","upgradeAtPowerCycle")] as part of the definition of the parameter means that is can only be one of these two options – this is much easier than doing a switch on the variable.

Line 36-40: This part is the same for all of the VM’s that will be processed – that is why it is part of the processed at the beginning of the script.

I would also like to thank Damian Karlson for his post on this subject which was helpful.

The reason why I wrote this small function .. - well that is for another post.

As usual your comments are always welcome.