Perform VMFS UNMAP using PowerCLI


I recently wrote a post on Automatic Space Reclamation (VMFS UNMAP) that was introduced in vSphere 6.5 and I got a lot of good response from the readers. The article can be found here.

To use Automatic Space Reclamation, you need to have a VMFS6 datastore which is available only with vSphere 6.5. So, if you have VMFS5 datastores, then you still have to do this using esxcli on the ESXi host.

While discussing with one of the readers, they wanted to if there was a script that would perform space reclamation on all datastores connected to an ESXi host?

There are plenty of scripts available online that do the job, but nobody had written a function that would do the same job.

Hence, I decided to write one and the article is titled Perform VMFS UNMAP using PowerCLI.

The function is shown below and it accepts two parameters at this time, which are the ESXi hostname and the Datastore name.

Before you run this command, make sure that you are connected to a vCenter Server using the Connect-VIServer command.

Using the Set-PowerCLIConfiguration we are disabling the timeout as the reclamation operation can go on for hours depending on how much space can be reclaimed from the thin-provisioned LUN from the array.

The command can be used as shown below.

Perform-VMFSUnmap -ESXiHost ESXi65-A.lab.local -Datastore ISOs

Perform VMFS UNMAP using PowerCLI

As you can see from the output, the command ran successfully but it errored out in my case because the datastore created from the backend LUN is not thin-provisioned.

This is because on my lab environment. I am using OpenFiler as a Virtual Appliance to present the LUNs to the ESXi hosts. So, ideally, you should not have any problems running this in your environment when you have thin-provisioned LUNs created.

I hope this has been informative and thank you for reading!


About Author

I am Adil Arif, working as a Technical Support Engineer at VMware as well as an independent blogger and founder of Enterprise Daddy. In my current role, I am supporting infrastructure related to Windows and VMware datacenters.

Leave A Reply

If so, please join the community.  I’d love to send you exclusive content right to your email, and I’ll send you a free copy of my book, VMware vSphere 6.0 Lab on Workstation too!
Enter your name and email below, and I’ll see you on the inside!