Skip to content

Instantly share code, notes, and snippets.

@msmorul
Created August 3, 2015 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msmorul/c97a51f9c5884eec60e1 to your computer and use it in GitHub Desktop.
Save msmorul/c97a51f9c5884eec60e1 to your computer and use it in GitHub Desktop.
#
# Print a summary of disk usage in the supplied directory
# -directory <directory>
#
Param(
[parameter(Mandatory=$true)]
[alias("d")]
$directory
)
gci $directory | %{$f=$_; $d = gci -r $_.FullName; $r = Measure-Object;try { $r = %{ $d | measure-object -property length -sum -ErrorAction Stop }} catch { $r.Sum = 0; } ; $r | select @{Name="Name"; Expression={$f}} , @{Name="Sum (MB)"; Expression={ "{0:N3}" -f ($_.sum / 1MB) }}, Sum } | sort Sum -desc | format-table -Property Name,"Sum (MB)", Sum -autosize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment