Calculating Space Consumption

by Feb 19, 2009

If you ever wanted to find out which folder in your profile consumes the most space (or want to check user profiles to make sure people do not overuse your resources), you can use this rather long pipeline command:

Get-Childitem $home | Where-Object { $_.PSisContainer } | 
  ForEach-Object { 
    Write-Progress 'Examining Folder' ($_.FullName</span>); $_ } | 
  ForEach-Object { $result = '' | 
    Select-Object Path, Count, Size;
    $result.path = $_.FullName</span>; 
    $temp = Get-Childitem $_.FullName -recurse -ea SilentlyContinue | 
    Measure-Object length -sum -ea SilentlyContinue ; 
    $result.count = $temp.Count</span>; 
    $result.Size = $temp.Sum</span>; 

It enumerates all folders in your $home folder and then calculates for each the size including all subfolders. Depending on the size of your profile, this may take some time. Meanwhile, a status message keeps you updated on the progress.