Yesterday I had the unpleasant experience of having to go through my email to find an email I wrote back in February 2011 in which I detailed the steps required in order to perform an offline update of VMware ESXi hosts via PowerCLI. Had I posted the steps here on this site at the time, it would have saved me a lot of pain in trying to retrieve the email from an Enterprise Vault archive! So, as I have learned my lesson, I am posting the steps required to update ESXi from PowerCLI.
At the time of writing the instructions, the update that I was looking at was ESXi 4.1 Update 1. However, the steps below will work on all newer ESXi versions as well.
VMware provides offline updates that can be downloaded from their website in the form of .ZIP archives. These updates can be downloaded from:
http://www.vmware.com/patchmgr/download.portal
Prerequisites
In order to perform the update with PowerCLI, you will need to have Windows PowerShell and PowerCLI installed on a workstation. Most VMware administrators will already have this installed.
Windows PowerShell:
If you are using Windows XP, PowerShell can be found on the Microsoft Website. If you are using Windows 7, Windows PowerShell 2.0 is already installed as part of the OS.
VMware PowerCLI:
Once PowerShell has been installed on your workstation, you will have to download and install VMware PowerCLI. You can download PowerCLI from here:
http://communities.vmware.com/community/vmtn/vsphere/automationtools/powercli
Steps to apply an offline update, in this case ESxi4.1 Update 1, to ESXi via PowerCLI:
1. Place the host that is going to be upgraded in Maintenance Mode.
2. Download ESXi 4.1 Update 1 from here:
https://hostupdate.vmware.com/software/VUM/OFFLINE/release-260-20110127-912579/update-from-esxi4.1-4.1_update01.zip
3. Using a utility such as WinZip or 7Zip, extract the downloaded file to a new folder on your C:\drive
4. Using the vSphere client, copy the files that were extracted to a folder called “Patches” on any datastore on the SAN that is visible to the host. This can also be placed on a local disk on the ESXi host, however, by placing the updated on shared storage will allow you to update more hosts from the same set of update files, without having to copy the files to each host.
5. Open the PowerCLI Console from your Start menu.
6. When the prompt pops up, connect to the vCenter server where the ESXi host is being managed from using the following command (you can also connect directly to the host if you like):
Connect-VIServer <VCENTER-SERVER NAME OR IP>
7. After the command has been issued, you might be prompted for a username and password.
8. Apply the patch with the following command:
9. Install-VMHostPatch –VMhost <ESXi name or IP Address> -HostPath /vmfs/volumes/<datastore-name>/Patches/metadata.zip
Note: I have seen a lot of cases where administrators try to point Install-VMHostPatch directly to the update zip archive downloaded from the VMware website. This will not work. You have to extract the archive, copy all of the data to a location that is accessible to the host to be updated, and point Install-VMhostPatch to the metadata.zip file.