Hyper-V PowerShell One-Line-Challenge - Part 3

After posting my Hyper-V one-line PowerShell snippets last week - I had numerous people ask me: "Can you make this export to a CSV file?".  How could I resist the ability to make this command even longer?  So here you are:

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)}} | Export-CSV VHDData.csv -NoTypeInformation

This single line of PowerShell will:

  1. Get all disks in the physical computer
  2. List the drive letters of each disk
  3. Report the free space on each disk (formatted to gigabytes)
  4. Finds all virtual hard disks that Hyper-V knows about on each disk and displays how much space they are using (formatted to gigabytes)
  5. Calculate how much space would be needed to fully expand all dynamically expanding disks
  6. Saves all of this in "VHDData.csv"

Cheers,
Ben

Comments

  • Anonymous
    April 15, 2015
    You think you're being clever by creating this when in fact this is a debugging nightmare

  • Anonymous
    April 15, 2015
    That does not mean I am not being clever...

  • Anonymous
    April 15, 2015
    I've got some reporting code I wrote earlier (hvreport.codeplex.com) which could be condensed to fit in there somewhere and probably still works.

  • Anonymous
    April 16, 2015
    The comment has been removed

  • Anonymous
    April 16, 2015
    Learn Perl - and write real one-liners: www.math.harvard.edu/.../oneliners.txt

  • Anonymous
    May 20, 2015
    Physical drives- I've several software-encrypted "drives" that I use often, if I wanted to also include these, what would I have to change to see them as well?  They all show up as regular drives in "this PC" so it should be fairly direct.