I needed to look at my virtual machines & their disk sizes – with Windows 2012 R2 upgrade in the works I need to do a bit more tidy up
I found two cmdlets in the Hyper-V module:
get-vmharddiskdrive – can be related to the virtual machine but doesn’t give a size
get-vhd – expects a path to the VHD file
Luckily get-vmharddiskdrive outputs the path. This gives me a nice pipeline:
Get-VM |
Get-VMHardDiskDrive |
Get-VHD |
select Path, @{N=’Size’; E={[math]::Round(($_.FileSize / 1gb), 2) }} |
sort -Descending
Get the VMs pipe through get-vmharddiskdrive and get-vhd then select and sort and you’re done.
I always break my pipelines at a pipe symbol – it acts as a line continuation in the console and ISE so anything thing else is just extra unnecessary work
I always break my pipelines at a pipe symbol, and indent all but the first line of the pipeline. This way every oneliner is a paragraph in my script. good for readabitlity.