In our PowerCLI book we presented a Delete-Harddisk function in Chapter 7.
One of our readers asked if that function could be used to remove orphaned VMDK files from one or more datastores. Now unfortunately that is not the case since the function we presented in chapter 7 uses the ReconfigVM_Task method to remove the harddisk.
In the PowerCLI Community there are some thread that provide scripts to report on orphaned VMDK files, but most of these are quite old.
So I decided to write a new script that would report on orphaned folders and VMDK files and that would have an option to remove these folders and files.
Last Sunday there appeared an interesting thread in the VMTN PowerCLI Community where one the questions was how to find all ‘Thin‘ virtual disks without passing via a virtual machine. The reason for this question was that most of the user’s virtual machines in Lab Manager are not registered on the vCenter Server.
My first idea was to use ‘Get-Datastore | Get-Harddisk‘ and then use the Extensiondata property to query the thinProvisioned property. Something like Arne did in his PowerCLI: Virtual Machine Disk (VMDK) info post. But that, unfortunately, doesn’t work since the Extensiondata property is $null in this case.
I know there are already numerous scripts to report on virtual hard disks and most of them without a doubt much better then what I came up with for this post.
The reason I started with this script was a question in the PowerCLI Community from Alan in his Thin Provisioned Disks post. He wanted to know if you could get the provisioned and the allocated disk size for a thin provisioned virtual disk.