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
    )

    # ponytail: without this, a typo'd -Path returned an empty list indistinguishable from a real
    # empty folder - Get-ChildItem's error was swallowed by -ErrorAction SilentlyContinue (which
    # is there on purpose, for the unreadable subfolders further down). Say so explicitly.
    if (-not (Test-Path -LiteralPath $Path)) {
        Write-Host "Path not found: $Path"
        return [pscustomobject]@{ Status = 'PathNotFound'; Path = $Path }
    }

    $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
}