Upgrade ESXi from 4.0 to 4.1 with PowerCLI, including Dell ESXi Agent Upgrade
Using VMware Update Manager to upgrade ESXi from 4.0 to 4.1 is a pretty straightforward process, but what about if you need to complete other tasks as part of the upgrade.
For instance, if you are running Dell Hardware then the ESXi agent also needs to be upgraded from version 6.2 supplied for ESXi 4.0 to 6.4 supplied for ESXi 4.1. You may also see some changes in advanced parameters between the two ESXi versions that you need to amend after the upgrade - I blogged about some of these before.
With PowerCLI you can issue commands to Update Manager, install OEM Agent packages and set advanced options. The following script will carry out an ESXi upgrade to 4.1 using an Update Manager Upgrade Package, install the Dell ESXi Agent for 4.1 and set the advanced parameter Scsi.CRTimeoutDuringBoot which changed from 4.0.
The Dell Agent needs to be on an accessible datastore. In this example I connected to an NFS share with ISOs and agent files; it could be a local or SAN datastore if you need to change it.
This process requires a reboot after each of the three steps. The first is handled by Update Manager which doesn’t complete the Remediation task until the host is back in vCenter, the second effectively includes a pause whilst we check the Connectionstate of the host until it is back in vCenter.
<# .SYNOPSIS Upgrade an ESXi 4.0 host to 4.1 U1
.DESCRIPTION Upgrade an ESXi 4.0 host to 4.1 U1 via Update Manager, including Dell Agent Upgrade
.Author Jonathan Medd
.PARAMETER Hostname The name of the host to upgrade.
.PARAMETER vCenter Enter the name of the vCenter server to connect to
.PARAMETER Base Enter the name of the Update Manager Upgrade Baseline
.PARAMETER Foldername Enter the name of the Dell ESXi Agent folder
.EXAMPLE PS C:\\> Update-ESXi40to41.ps1 -Hostname ESX01 -vCenter vCenter01
#>
#requires -pssnapin VMware.VimAutomation.Core #requires -pssnapin VMware.VumAutomation
\[CmdletBinding()\] param( \[Parameter(Position=0, Mandatory=$true, HelpMessage="Enter the name of the host to upgrade")\] \[String\] $Hostname, \[Parameter(Position=1, Mandatory=$true, HelpMessage="Enter the name of the vCenter server to connect to")\] \[String\] $vCenter, \[Parameter(Position=2, HelpMessage="Enter the name of the Update Manager Upgrade Baseline")\] \[String\] $Base = '4.0 -> 4.1 U1 Upgrade', \[Parameter(Position=3, HelpMessage="Enter the name of the folder containing the Dell Update")\] \[String\] $FolderName = "OM-SrvAdmin-Dell-Web-6.4.0-1266.VIB-ESX41i\_A00.7" )
process{
Connect-VIServer $vCenter
$VMHostObj = Get-VMHost $Hostname $Baseline = Get-Baseline $Base
if ($VMHostObj | Get-Datastore NFS\_Share -ErrorAction SilentlyContinue){ Write-Host "NFS\_Share Datastore found" }
else { Write-Host "NFS\_Share Datastore not found, please connect it and run the script again" exit }
\# Put host into Maintenance Mode Write "Putting host into Maintenance Mode" Set-VMHost $VMHostObj -State Maintenance -Confirm:$false | Out-Null
\# Attach the Upgrade Baseline Write-Host "Attaching baseline" $Baseline | Attach-Baseline -Entity $VMHostObj
\# Scan the host Write-Host "Scanning host for updates" $VMHostObj | Scan-Inventory
\# Apply the 4.0 - 4.1 Upgrade Write-Host "Patching host" $Baseline | Remediate-Inventory -Entity $VMHostObj -Confirm:$false | Out-Null
\# Upgrade Dell OMSA from the NFS Templates share Write-Host "Upgrading Dell OMSA Client" $VMHostObj | Install-VMHostPatch -HostPath /vmfs/volumes/NFS\_Share/Dell/$FolderName/metadata.zip
\# Reboot after the Dell OMSA install Restart-VMHost $VMHostObj -Confirm:$false | Out-Null Write-Host "Waiting 2.5 minutes for $Hostname to reboot" Start-Sleep 150
\# Check the state of the host until it is back into vCenter $VMHostState = (Get-VMHost -Name $Hostname -ErrorAction SilentlyContinue).ConnectionState
While ($VMHostState -eq "NotResponding"){ Write-Host "ESXi Server state is" $VMHostState Write-Host "Waiting 20 seconds until ESXi Server starts responding" Start-Sleep 20 $VMHostState = (Get-VMHost -Name $Hostname).ConnectionState }
\# Set Advanced Options Write-Host "Setting Option Values" Set-VMHostAdvancedConfiguration -VMHost $Hostname -Name Scsi.CRTimeoutDuringBoot -Value 1 | Out-Null
\# Reboot to finish Write-Host "Rebooting to finish" Restart-VMHost $VMHostObj -Confirm:$false | Out-Null
}