ESXCLI updates in PowerCLI 6.3 R1

One of the changes in VMware vSphere PowerCLI 6.3 R1 was a much needed one: how the arguments are managed with esxcli commands. This was always a bit of a pain, especially for commands that have a lot of arguments. I won’t go into the detail on all of why/what of the changes here, as Alan Renouf already did that quite well here. So if you are unsure of the previous ugliness of esxcli in PowerCLI read that post before reading more here. Otherwise, continue on. I want to talk about some specific examples for storage-related commands that I use and many of our customers use quite commonly.

The most common storage esxcli commands I use are:

  • Setting a SATP rule
  • Running UNMAP
  • Resignaturing volumes

A final quick note at the end too concerning the differences in behavior of just listing information.

Let’s run through how to do this with V2 of esxcli in PowerCLI.

SATP Rule Configuration

The original line for creating a SATP was the following:

$esxcli = get-vmhost "10.21.10.107" | get-esxcli
$esxcli.storage.nmp.satp.rule.add($null, $null, "PURE FlashArray IO Operation Limit Rule", $null, $null, $null, "FlashArray", $null, "VMW_PSP_RR", $iops, "VMW_SATP_ALUA", $null, $null, "PURE")

Ugly. The new way is a few more commands, but much more intuitive.

The get-esxcli portion changes just slightly, by adding the -v2 switch:

$esxcli = get-vmhost "10.21.10.107" | get-esxcli -v2

Then you need to get the settings that are available, this is through the “createArgs() operation:

$satpArgs = $esxcli.storage.nmp.satp.rule.add.createArgs()

$satpArgs will now list the possible options for this command, as shown below:

satpargs

Then populate the parameters you want into the stored hashtable:

$satpArgs.description = "Pure Storage FlashArray SATP Rule"
$satpArgs.model = "FlashArray"
$satpArgs.vendor = "PURE"
$satpArgs.satp = "VMW_SATP_ALUA"
$satpArgs.psp = "VMW_PSP_RR"
$satpArgs.pspoption = "iops=1"

Then you can create the rule:

$esxcli.storage.nmp.satp.rule.add.invoke($satpArgs)

The nice thing is you can continue to re-use that argument hashtable if you need to run it on more than one host. Makes the script much simpler to read, with less garbage (not a bunch of $null everywhere).

UNMAP

UNMAP is another one of those esxcli commands I use quite frequently. The UNMAP command though has a lot less arguments so the enhancement is less impactful, but still will need to be converted at some point when the old way deprecates. UNMAP has three arguments, VMFS name, block count and UUID. You need to enter name or UUID and block count is optional.

$esxcli.storage.vmfs.unmap("2000", "my datastore", $null)

Just as above, the get-esxcli portion changes just slightly, by adding the -v2 switch:

$esxcli = get-vmhost "10.21.10.107" | get-esxcli -v2

Then you need to get the settings that are available, this is through the “createArgs() operation:

$unmapArgs = $esxcli.storage.vmfs.unmap.createargs()

That hashtable looks like below:

PowerCLI C:\> $unmapargs

Name                  Value
----                       -----
volumelabel         Unset, ([string], optional)
reclaimunit           Unset, ([long], optional)
volumeuuid          Unset, ([string], optional)

Then populate the information in the hashtable inside of $unmapArgs:

$unmapargs.volumelabel = "SRMPlaceholder"
$unmapargs.reclaimunit = "9900"

I am not using the UUID, I am using the VMFS name (label) and I am entering a block count. Run the command passing in the args finally:

$esxcli.storage.vmfs.unmap.Invoke($unmapargs)

Resignaturing an Unresolved VMFS volume:

I’ve posted about this topic many times before (this post here being the first part in a recent series of posts). This one is very similar to above but with even less arguments.

Just as above, the get-esxcli portion changes just slightly, by adding the -v2 switch:

$esxcli = get-vmhost "10.21.10.107" | get-esxcli -v2

Then you need to get the settings that are available, this is through the “createArgs() operation:

$resigArgs= $esxcli.storage.vmfs.snapshot.resignature.CreateArgs()

That hashtable looks like below:

PowerCLI C:\> $resigArgs
Name                  Value
----                       -----
volumelabel         Unset, ([string], optional)
volumeuuid          Unset, ([string], optional)

Then populate the information in the hashtable inside of $unmapArgs:

$resigArgs.volumelabel = "DatastoreCopy"

I am not using the UUID, I am using the VMFS name (label) so that’s all I need. Pass that into the resignature command and you’re done.

$esxcli.storage.vmfs.snapshot.resignature.invoke($resigArgs)

Easy enough.

Listing results

Once last thing, listing results is now longer what it used to be where you can just end the command in “.list” and it will run. You need to append “.invoke()” to get the results. So in v1 it looked like:

$esxcli.storage.nmp.satp.rule.list()

The new way is as such:

 $esxcli.storage.nmp.satp.rule.list.invoke()

Note that the new way seems to be backwards compatible with v1.

7 Replies to “ESXCLI updates in PowerCLI 6.3 R1”

    1. Yep! Working on that right now actually. The best practices script should be posted later today hopefully and the UNMAP one will be updated in the next few days.

  1. Hi, just one question.

    “Then populate the parameters you want into the stored hashtable:”
    could you specify that?

    I have an error
    If specified, the arguments parameter must contain a single value of type Hashtable.

    Thank you

Leave a Reply to Lorenzo Benaglia Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.