The cost of hard disk is getting cheaper day by day. Even if we have terabytes of disk space, one fine day it is gonna be full.

The difficult job is to find which folder has used more space. Out in the market, there are many tools for analyzing the disk space utilization. The one which I like is TreeSize.

Did you know that few lines of PowerShell script could do the same?

Detailed script with exception handling

$path = "C:\Users\" 
$depth = 1 
$result = @() 

$folders = (Get-ChildItem -Path $path -Directory -Recurse -Depth $depth).FullName 
$folders | % {     
    try {         
        $size = Get-ChildItem -Path $_ -File -Recurse -ErrorAction SilentlyContinue | measure-object  -property length -Sum | select @{Name="Sum"; Expression={[Math]::Round($($_.Sum/1gb), 2)}}         
        if($size -eq $null) {             
            $result += $_ | Select-object @{Name="Path";Expression={$_}}, @{Name="Size(gb)";Expression={0}}         
            }         
        else {             
            $result += $_ | Select-object @{Name="Path";Expression={$_}}, @{Name="Size(gb)";Expression={$Size.Sum}}         
            }     
        }     
        catch [System.Exception] {         
            "Access Denied to - " + $_     
            } 
        } 
#condition to filter -- below sample shows folder occupying 1GB+ data
$result | Where {$_."Size(gb)" -gt 1} | Sort-Object "Size(gb)" -Descending

Hope this helps you…