Geaux Virtual

Helping virtualize the datacenter…

Follow up on ESXCLI with PowerCLI

with 3 comments

In a previous post here, Applying Patches to ESXi 5 with the help of PowerCLI, I showed how simple it was to call ESXCLI that is part of vCLI through a PowerCLI script, but did you know that ESXCLI is also part of PowerCLI?

ESXCLI is actually part of the VMware API for an ESXi host. Note: While the API for vSphere 4 also had ESXCLI included, it is much more robust with vSphere 5. Most if not all of the commands I show will only work against vSphere 5. PowerCLI has a cmdlet called Get-EsxCli that can be used when connected directly to an ESXi host.

First, connect to an ESXi host through PowerCLI.

Connect-VIServer

Next, lets run the Get-EsxCli cmdlet.

$esxcli = Get-EsxCli

Now we have our ESXCLI object. Now what can we do with it? Well basically anything that you would do with ESXCLI through vCLI or local to the ESXi host. So let’s say our host is running on a Cisco UCS system, and we wanted to verify the enic driver version loaded on the host. We could issue the following command to view the driver version.

$esxcli.system.module.get("enic").version

Now, to follow-up on the previous post, we could use the $esxcli object obtained through PowerCLI to issue the commands to view the vibs on the host and apply vibs to the host in the same manor that we were calling ESXCLI before. If we wanted to see all the VIBs installed on a host, we can issue the following command to give us the name, vendor, and version of all VIBs installed on the host in formatted table output.

$esxcli.software.vib.list() | ft Name,Vendor,Version

Let’s look at the example from the previous blog post. Here we set the patch name and location of the patch on the datastore that the host could access.

$patch = "PatchFile.zip" #patch file we want to apply
$datastore = "datastore1" #datastore where we want to store the patch
$remoteLocation = "/vmfs/volumes/" + $datastore + "/" + $patch #remote location of patch

Now once the patch is on the datastore, which I covered in the previous post, you could install it with the command

$esxcli.software.vib.install($remoteLocation)

Here is another tip as well for PowerShell and PowerCLI. If you are unsure of the arguments that a function takes, such as the command above, you can run

$esxcli.software.vib.install

and the command will output some useful data about the method. One particular useful output is Value. This tells you what the expected value type will be given the proper inputs. For the above command, you can see the output as follows:

Hopefully this proves useful to someone.

Advertisement

Written by jguidroz

March 12, 2012 at 9:12 am

Posted in Scripting, VMware

3 Responses

Subscribe to comments with RSS.

  1. Did you actually try this and confirm it works ? Because I do not think your esxcli.software.vib.install() will work .. To date I don’t know of anyone who has gotten vib install to work from powerCLI ..

    Narayan Venkat

    March 27, 2012 at 9:54 am

    • Yes. I tested this before posting this article. For different patches, other options may need to be set such as maintenance mode, etc. The available options can be seen in the screenshot in the article.

      jguidroz

      March 28, 2012 at 9:31 am

  2. I tried it last night and it worked for me.
    Great job!

    gopi

    April 15, 2012 at 6:20 am


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 )

Connecting to %s

%d bloggers like this: