I found these 2 threads that seem promising:
However, neither does precisely what I want (report on non-thin disks only).
I tried combining elements from both of these posts into my own script:
$report = foreach ($vm in Get-VM | Where-Object{$_.Name -notlike 'stCtlVM-*'}) {
$disks = Get-HardDisk -VM $vm
foreach ($disk in $disks) {
if ($disk.StorageFormat -ne 'Thin') {
[PSCustomObject]@{
Server = $vm.Uid.Split(":")[0].Split("@")[1]
VMName = $vm.Name
VMId = $vm.Id
FileName = $disk.FileName
CapacityGB = $disk.CapacityGB
FreeSpaceGB = $disk.CapacityGB - (($vm.extensiondata.layoutex.file|?{$_.name -contains $disk.filename.replace(".","-flat.")}).size/1GB)
}
}
}
}
$report | Sort-Object Server, VMName | Export-Csv -LiteralPath $file -NoTypeInformation -UseCulture -Force
The issue is "FreeSpaceGB" is typically either identical to "CapacityGB" or a negative number, indicating my math isn't correct.