public/Show-OctaDiskUsage.ps1
|
function Show-OctaDiskUsage { <# .SYNOPSIS Read-only "top N largest folders" report (research.md) - the CLI-appropriate equivalent of Kudu's graphical treemap. Real recursive measurement, no estimates. #> [CmdletBinding()] param( [string]$Path = $env:USERPROFILE, [int]$Top = 10 ) $subFolders = Get-ChildItem -LiteralPath $Path -Directory -ErrorAction SilentlyContinue $sizes = foreach ($folder in $subFolders) { $sum = (Get-ChildItem -LiteralPath $folder.FullName -File -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum [pscustomobject]@{ Path = $folder.FullName; SizeBytes = [int64]($sum) } } $topFolders = @($sizes | Sort-Object SizeBytes -Descending | Select-Object -First $Top) foreach ($f in $topFolders) { Write-Host ("{0,10:N0} MB {1}" -f [Math]::Round($f.SizeBytes / 1MB, 0), $f.Path) } return $topFolders } |