Freigeben über


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

Comments

  • Anonymous
    April 08, 2015
    It seems that a considerable amount of your recent Powershell examples do not apply to older versions of Powershell (including Windows 7). Can you please provide the Windows 2008 R2 equivalent of the above?

  • Anonymous
    April 11, 2015
    Hey Ben, can you modify the oneliner to split out CSVs as well? If you have a number of volumes on a clustered hyper-v host, everything shows up aggregated under C: with this oneliner.  Thank you!

  • Anonymous
    April 12, 2015
    Microsoft did not provide Hyper-V PowerShell cmdlets in Windows Server 2008 R2.  I suspect that you are using a 3rd party PowerShell module.

  • Anonymous
    April 13, 2015
    Get-Volume doesn't work either. In Server 2008 or Windows 7 (PowerShell 4.0.)