PowerActions–The PowerCLI Plugin for the vSphere Web Client with UNMAP

The other day I stumbled upon a new VMware labs “Fling” called PowerActions. Basically it allows you to run in-context PowerShell/PowerCLI scripts right from within the vSphere Web Client. My mouth drooled at the promise of what this could deliver–and it really delivered! This is my new favorite tool by a landslide. See the announcement here from @alanrenouf http://www.virtu-al.net/2014/09/16/powercli-vsphere-web-clientannouncing-poweractions/. I’d recommend readin this first before you continue down with my post.



I am not going to go into how to install and configure (it is extremely easy to do), so refer to this post here for a walkthrough on that:


Basically you need a Windows Server that has PowerCLI installed. There are some current limitations (must have .net 4.0 and PowerShell 2 or 3), but it seems supporting newer versions is on the roadmap. So I would suggest just using Windows Server 2008 R2 as 2012 has .net 4.5 installed by default.

The VERY first thought I had with this was introducing UNMAP into the vSphere Client, since as of now it is only a CLI option. Of course @lamw–who I have exchanged a few emails with about UNMAP in the Web Client recently–already beat me to it here. So I decided to take it a few steps further.

On any All-Flash-Array with data reduction (or really just anything with thin provisioning) UNMAP is a very important part of managing your storage–especially in environments that have a lot of virtual machine turnaround so to speak. Running a CLI command all the time is somewhat annoying and requires a few steps that takes you out of your normal operating environment (the Web Client).

So I wrote a PowerCLI script that does the following:

  1. Is initiated by right-clicking a cluster object and choosing the script option
  2. Asks the user for what block iteration to use for the UNMAP procedure
  3. Looks for all of the datastores in the cluster
  4. Filters out any datastore that is not on a Pure Storage volume
  5. Goes through each datastore one by one and reclaims space on them

Pretty simple but really saves a lot of time if you are often running UNMAP. Easy and convenient!

So let’s walk through it.

First you create a new script in the plugin screen. I have two already created as you can see below:


The first option you choose in the menu is what object in the vCenter inventory should this appear and be allowed to run against? A datastore? A VM? A cluster? The whole vCenter? Up to you. For this I wanted to choose a cluster.


Then you name the script and give it a description. Also choose if it is an “action” or a “report” this way you know when you run the script later if it will change something or just look at stuff.


Now we can actually write our script. You can write it in the wizard or anywhere–I used ISE and then copy/pasted it in. A few notes on writing PowerShell for this–it does weird things with write-host where if you combine objects and text it does some weird new line stuff–so you have to workaround that a bit. You’ll see what I did in my script to get around it.


The cool thing is that it automatically imports whatever object you selected in the wizard as an object you can quickly use in the script. It saves it as $vParam. In this case it was my cluster (so the cluster you end up right-clicking). You can change whatever you want in the lines it inserts–you don’t have to use the $vParam naming convention etc.

The script I wrote can easily be changed to work on just one ESXi host, or iterate through and entire vCenter. A single datastore is really easy to do. Also note, it is already connected to the vCenter so you don’t have to do the connect-viserver stuff.

So to kick it off just right-click the cluster and choose the PowerCLI menu option, then the correct script. Only the ones assigned to a cluster object will appear.



The script will immediately start running. My script asks the user just one thing–the block count for UNMAP (note this script is only for ESXi 5.5 with esxcli UNMAP).



unmapcluster Just a docx file. The script is pasted below as well.

Here is a video of it in action–there is a voice over, but the video itself is pretty self-explanatory without audio:

So many more things I want to do with this, stay tuned!


write-host "--------------------------------------------------------------------------" 
$textoutput = "Initiating VMFS UNMAP for all Pure Storage volumes in the cluster named " + $vParam.name
write-host $textoutput
write-host "Searching for VMFS volumes to reclaim (UNMAP)"
$datastores = get-cluster $vParam |get-datastore
$textoutput = "Found " + $datastores.count + " VMFS volume(s)."
write-host $textoutput
write-host "Iterating through VMFS volumes and running a reclamation on Pure Storage volumes only"
$textoutput = "UNMAP will use a block count iteration of " + $UNMAPBlockCount
write-host $textoutput
$textoutput = "Please be patient, this process can take a long time depending on how many volumes and their capacity"
write-host $textoutput
foreach ($datastore in $datastores)
    $esx = get-datastore | get-vmhost |Select-object -first 1
    $lun = get-scsilun -datastore $datastore 
    $esxcli=get-esxcli -VMHost $esx
    if ($lun.canonicalname -like "naa.624a937*")
       write-host "--------------------------------------------------------------------------" 
       $textoutput = $datastore.name + " is a Pure Storage Volume and will be reclaimed."
       write-host $textoutput
       write-host "Initiating reclaim..." 
       $esxcli.storage.vmfs.unmap($UNMAPBlockCount, $datastore, $null) |out-null
       write-host "Reclaim complete"
       write-host "--------------------------------------------------------------------------"
       $textoutput = $datastore.name + " is not a Pure Volume and will not be reclaimed. Skipping..."
       write-host $textoutput
write-host "--------------------------------------------------------------------------"
$textoutput = "Reclamation finished. A total of " + $volcount + " Pure Storage volume(s) were reclaimed"
write-host $textoutput

6 Replies to “PowerActions–The PowerCLI Plugin for the vSphere Web Client with UNMAP”

  1. Thanks for the wonderful Script. I copy/paste the given content and ran the script, it didn’t gave me any output or the running screen. It simply freeze the WebClient.

    1. You’re welcome! I wrote this a few years ago, so I’d say it probably needs to be updated. I will have to test it

  2. Thanks Codyhosterman. Did you get a chance to test the script ?
    Problem – it didn’t gave me any output or the running screen. It simply freeze the WebClient

    1. I haven’t unfortunately. Due to other activities I do not think I will be able to get to it for some time.

Leave a 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.