Created
November 1, 2023 00:17
-
-
Save Announcement/d3526f6ec8a105575c5b2461c7c631d2 to your computer and use it in GitHub Desktop.
What's taking up all my space? Sorts biggest folders, and files inside the folders, with a low-pass filter.
This file contains 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
Get-ChildItem -Recurse -Depth 2 | Where-Object -Property Length -GT 1MB | % { [pscustomobject]@{Length=$_.Length;Folder=$(Resolve-Path -Path $_.Directory -Relative).Replace('.\','');Name=$_.Name} } | Group-Object Folder | % {[pscustomobject]@{Name=$_.Name;Size=$_.Group | Measure-Object -Property Length -Sum | Select-Object -ExpandProperty Sum;Files=$_.Group|Sort-Object -Property Length}} | Sort-Object Size | % { $Folder=$_;$_.Files | % { [pscustomobject]@{Length=$_.Length;Folder=$Folder.Name;Name=$_.Name} } } | Format-Table @{n='Length';e={Format-FileSize $_.Length};align='right'},Name -GroupBy Folder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Get-ChildItem -Recurse -Depth 2 | Where-Object -Property Length -GT 1MB | % { [pscustomobject]@{Length=$.Length;Folder=$(Resolve-Path -Path $.Directory -Relative).Replace('.','');Name=$.Name} } | Group-Object Folder | % {[pscustomobject]@{Name=$.Name;Size=$.Group | Measure-Object -Property Length -Sum | Select-Object -ExpandProperty Sum;Files=$.Group|Sort-Object -Property Length}} | Sort-Object Size | % {$Folder=$ ;$.Files | % { $File=$ ;[pscustomobject]@{File=[pscustomobject]@{Name=$File.Name;Length=$File.Length};Folder=[pscustomobject]@{Name=$Folder.Name;Length=$Folder.Size}} } } | Format-Table @{n='Length';e={Format-FileSize $.File.Length};align='right'},@{n='Name';e={$.File.Name}} -GroupBy @{n="Folder";e={"$($.Folder.Name) [$(Format-FileSize $_.Folder.Length)]"}}