Calculating Space Consumption

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); $_ } |
ForEach-Object { $result = '' |
Select-Object Path, Count, Size;
$result.path = $_.FullName;
$temp = Get-Childitem $_.FullName -recurse -ea SilentlyContinue |
Measure-Object length -sum -ea SilentlyContinue ;
$result.count = $temp.Count;
$result.Size = $temp.Sum;
$result
}

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.


Posted Feb 19 2009, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.