Skip to content

Instantly share code, notes, and snippets.

@yeahservice
Last active December 21, 2019 22:47
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 yeahservice/d43cd561ff15cae9f39a86ab28b6de55 to your computer and use it in GitHub Desktop.
Save yeahservice/d43cd561ff15cae9f39a86ab28b6de55 to your computer and use it in GitHub Desktop.
Windows Powershell script for displaying directory sizes. Just copy it into the root directory and execute the script with Powershell.
Get-ChildItem -Directory | ForEach-Object {
"$_"
cd $_
switch((ls -r|measure -s Length).Sum) {
{$_ -gt 1GB} {
'{0:0.0} GB' -f ($_/1GB)
break
}
{$_ -gt 1MB} {
'{0:0.0} MB' -f ($_/1MB)
break
}
{$_ -gt 1KB} {
'{0:0.0} KB' -f ($_/1KB)
break
}
default { "$_ bytes" }
}
cd ..
""
}
Read-Host -Prompt "Press any key to exit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment