Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aev-mambro2/fa5fc36c01cfc83c8ba66b6cdbcdf324 to your computer and use it in GitHub Desktop.
Save aev-mambro2/fa5fc36c01cfc83c8ba66b6cdbcdf324 to your computer and use it in GitHub Desktop.
powershell-get-20-largest-folders-in-current-location
Function Get-FolderSize {
BEGIN { $fso = New-Object -ComObject Scripting.FileSystemObject }
PROCESS {
$path = $input.fullname
$folder = $fso.GetFolder($path)
$size = $folder.size
[PSCustomObject]@{ 'Name' = $path;'Size' = [math]::Round(($size / 1mb), 2) }
}
}
Get-ChildItem -Directory -Recurse -EA SilentlyContinue | Get-FolderSize | Where-Object {$_.Size -ge 1} | Sort size | Select -Last 20 | Format-List
@aev-mambro2
Copy link
Author

It isn't always easy to find which locations on a computer contain the most stuff, eating up all your disk space. This script is meant to help you analyze.

To use, start Powershell, navigate into any folder, and run. The script kicks back the largest folders. Navigate to the largest, and run again. Repeat until you find the one folder that needs emptying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment