So, you have installed ESX on your nice pair of RAID 1 72GB or 146GB disks and have a whole bunch of disk space left over, what do you do with it, well if your anything like me you will format it as a VMFS partition and use it for storing Templates or temporary VMs that you dont care if they die.

But what if your not like me, what if your one of those admins who doesnt really know where they are storing their VM’s, they dont even care, they just click to order the storage by free space and put it on the one that has the most free space – even if it is local storage (come on, we all know them).

The following one-liner will list all the VMDK files for VMs stored on your local storage.

Please note:  The where clause assumes your local storage has the word local in it, this can obviously be changed or you can use a –nomatch to exclude your san storage if needs be.

Get-Datastore |where {$_.Name -match local} |Get-VM |Get-HardDisk |select Filename |Export-Csv c:\LocalVMs.csv

You can also add multiple names for your local storage by added them with a | between them in the match string (Thanks LucD) like the following:

Get-Datastore |where {$_.Name -match store|local|storage} |Get-VM |Get-HardDisk |select Filename |Export-Csv c:\LocalVMs.csv