Last active
January 3, 2022 14:14
-
-
Save aev-mambro2/fa5fc36c01cfc83c8ba66b6cdbcdf324 to your computer and use it in GitHub Desktop.
powershell-get-20-largest-folders-in-current-location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.