Skip to content

Instantly share code, notes, and snippets.

@Announcement
Created November 1, 2023 00:17
Show Gist options
  • Save Announcement/d3526f6ec8a105575c5b2461c7c631d2 to your computer and use it in GitHub Desktop.
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.
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
@Announcement
Copy link
Author

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)]"}}

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