Update vSphere 5 hosts to U1 with Update manager and PowerCLI

Today I wanted to update my lab environment hosts to U1 of vSphere 5, of course with PowerCLI, there is no other way or is it?

This reference indicates there is not so many cmdlets but is it enough? Yes it is!

As the PowerCLI installation does not include the VUM cmdlets i had to download and install them

I have already upgraded my vCenter and VUM to U1, this as it is always a best practice to first update the vCenter and then the hosts

the following script do the whole process of both making a Patch baseline and attaching it to the cluster and then Scan/Remidate (now i only have two hosts but this is quite powerfull if i have lots of more). The script allows some parameters, for example if you already have a baseline you can use that and attach/remediate your cluster, or you want another patch in the baseline.

<#
 .SYNOPSIS
 Upgrade ESXi Hosts to an Update Version 

 .DESCRIPTION
 Create an baseline and upgrade a Cluster to an vSphere 5 update with Update Manager, If you already have a baseline just use the BaseName parameter

 .Author
 Niklas Akerlund /RTS 2012-03-23 (original script from Jonathan Medd)

 .PARAMETER  Cluster
 The name of the host to upgrade.

 .PARAMETER  PatchName
 Enter the name of the Patch/Update
 
 .PARAMETER Name
 Enter the name of the vCenter server to connect to

 .EXAMPLE
 PS C:\> Update-HostsU1.ps1 -Cluster VMWCL
#>
#requires -pssnapin VMware.VimAutomation.Core
#requires -pssnapin VMware.VumAutomation

[CmdletBinding()]
param(
 [Parameter(Position=0, Mandatory=$true, HelpMessage="Enter the name of Cluster")]
 $Cluster,
 [Parameter(HelpMessage="Enter the name of the patch")]
 [String]
 $PatchName = "VMware ESXi 5.0 Complete Update 1",
 [Parameter(HelpMessage="Enter the baseline name")]
 [String]
 $BaseName = "vSphere ESXi 5 U1"
 )

process{

	# Create a baseline to use
	if(!(Get-Baseline -Name $BaseName -EA 0)){
		# Get the update and add a Patchbaseline
		$Patch = get-patch | where {$_.Name -eq $PatchName}
		New-PatchBaseline -Name $BaseName -Static -IncludePatch $Patch
	}
	# Attach the baseline on the cluster
	$Cluster = Get-Cluster $Cluster
	$Baseline = Get-Baseline -Name $BaseName
	if($Baseline){
		$Baseline | Attach-Baseline -Entity $Cluster
		
		# Scan the Cluster 
		$Cluster | Scan-Inventory
		
		# Remediate the cluster with the baseline
		$Cluster | Remediate-Inventory -Baseline $Baseline -ClusterDisableDistributedPowerManagement:$true -ClusterDisableFaultTolerance:$true -ClusterDisableHighAvailability:$true -Confirm:$false -HostDisableMediaDevices:$true
		
	}
}

And here are some screenshots of it running,

One host successfully updated and the remediate migrates the VM´s and start with the other host.

Finally the hosts in the cluster are updated.

I have used some of the code from Jonathan Medd´s post on upgrading from 4.0->4.1 to create my script.