The snippet of code above will perform a SCSI UNMAP (old name) or VMFS UNMAP (new name) on a particular datastore. This is a task that should be scheduled and run multiple times per datastore to see any real benefit.

Some things to note:

$Size is how big of a block to work with – This is usually 200, 400, 800 or 1600. The bigger the block size, the more IOPS will be committed to the process. Be careful when using in a production environment and be sure to test!

$BeforeUsed is simply the amount of space the SAN says is in use before the VMFS UnMap command is run.

$AfterUsed is simply the amount of space the SAN says is in use after the command completes.

$lun and $vol are CASE Sensitive!

If there is any interest, I’ll add a new post with some samples of how to use this process in a scheduled task.