I have a script that retrieves details for all VMs in my vCenter Cluster. Essentially Get-VM | Get-Harddisk
.
I can also get the Provisioned Space
and Used Space
values, but these are only for the VM as a whole, and I'd like to get this per VMDK file on the actual SAN.
I have had some luck with ($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB
but this does not retrieve details for all my VMs, and I cannot workout why?
UPDATE 1:
So I have found that this information is available through $vm.ExtensionData.Storage.PerDatastoreUsage
. This returns an array of details of each datastore and shows how much disk is used. The issue now is that I don't know how to tally up which entry relates to which disk (other than manually checking). Its fine if each disk is on a different datastore, but when they are all on the same and of the same size (i.e. we have a Windows VM with 2 100GB Thin disks on same datastore) it proves more challenging.