Hyper-V PowerShell One-Line-Challenge – Part 2

Building on the Hyper-V PowerShell One-Liner that I posted on Monday – comes this even more complicated one-liner:

Get-Volume | ?{$_.DriveLetter -ne $null} | select @{N=’Drive Letter’;E={$_.DriveLetter}},@{N=’Free Space (GB)’;E={“{0:N2}” -f ($_.SizeRemaining / 1GB)}},@{N=’Space Used By VHDs (GB)’;E={$driveletter = $_.DriveLetter; “{0:N2}” -f ((Get-VMHardDiskDrive * | ? {$_.Path -match “^$driveletter” } | Get-VHD | Measure -sum FileSize | Select -exp sum)/1GB)}},@{N=’AllocatedToVHDs’;E={$driveletter = $_.DriveLetter; “{0:N2}” -f ((Get-VMHardDiskDrive * | ? {$_.Path -match “^$driveletter” } | Get-VHD | Measure -sum Size | Select -exp sum)/1GB)}}

What does it do?  Let’s see:

 

Just like the post from Monday, it shows you how much space is being used by virtual hard disks on each drive in the host.  But, on top of that it also shows how much space is allocated by any dynamically expanding virtual hard disks.  This makes it a very handy way to tell if you have oversubscribed your physical hard disks, and if yes – by how much.

Cheers,
Ben