Geaux Virtual

Helping virtualize the datacenter…

Applying patches to ESXi 5 with the help of PowerCLI

with 2 comments

So today, Chris Colitti posted a blog article about patching ESXi 5 without VUM. If you haven’t read it, I suggest you click this link and read his post.

After reading this post, I was surprised to find out that esxcli did not support pushing patch or extension files remotely. Prior to ESXi 5, you could use vihostupdate via the vCLI to install the patch or extension zip files to a host. With vSphere 5, vihostupdate has been deprecated. The esxcli command supports installing a patch or extension from a remote depot url (VUM for instance) or from a local file path on the server, as Chris pointed out. Another option would be to host the actual vib files on an http or ftp server and use the -v option with esxcli to point to the remote location of these files. However, this is not the point of this blog post. This blog post will talk about using PowerShell and PowerCLI to assist esxcli in installing patches remotely. I will not provide a whole script, but just some useful commands.

First, to make things easier, we’ll set a couple of variables.
$esxcli = "C:\Program Files\VMware\VMware vSphere CLI\bin\esxcli.exe" #location of esxcli
$server = "192.168.1.10" #server we want to patch
$patch = "PatchFile.zip" #patch file we want to apply
$patchLocation = "C:\" #local path to patch"
$datastore = "datastore1" #datastore where we want to store the patch
$remoteLocation = "/vmfs/volumes/" + $datastore + "/" + $patch #remote location of patch

Now, we want to mount a datastore to our workstation. First we need to connect to the ESXi host before doing anything.

Connect-VIServer $server
New-PSDrive -name "mounteddatastore" -Root \ -PSProvider VimDatastore -Datastore (Get-Datastore $datastore)

After we mount our datastore, we can then copy the patch to the datastore.

Copy-Datastoreitem $patchLocation + $patch -Destination mounteddatastore:

Once our file is copied, we can then execute esxcli to install our patch

& $esxcli --server $server software vib install -d $remoteLocation

This will execute esxcli on your workstation to install the patch we just uploaded to the datastore. Once the patch is installed, we can remove the patch and disconnect the datastore from the workstation.

del mounteddatastore:$patch
Remove-PSDrive -name "mounteddatastore" -PSProvider VimDatastore

So with this little bit of knowledge, you could write a PS script to copy the patch to a datastore (preferably shared across hosts), and then call esxcli to install the patch on the required hosts.

Update: A new blog post is up detailing using the Get-EsxCli cmdlet in PowerCLI. This can be located here.

About these ads

Written by jguidroz

December 2, 2011 at 4:16 pm

Posted in Scripting, VMware

2 Responses

Subscribe to comments with RSS.

  1. [...] option as well I just have not tried it, but  Justin Guidroz has posted a way to do so on his blog so check it out if you are a PowerCLI user.NOTE: If you try and use the old esxupdate command, [...]

  2. [...] option as well I just have not tried it, but  Justin Guidroz has posted a way to do so on his blog so check it out if you are a PowerCLI user.NOTE: If you try and use the old esxupdate command, [...]


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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: