Last week @beningus, also a Dutch PowerShell interested IT Pro, contacted me for some assistance troubleshooting a script.
The purpose of that script was to list the directories of, for example, the homedirs on a fileserver in order to find the “big spenders” among the users. For this, we’ve written the following function:
function Get-FolderLength
{
# Usage: Get-FolderLength.ps1 D:\Homedirs
param ( [Parameter(Mandatory=$true)] [String]$Path )
$FileSystemObject = New-Object -com Scripting.FileSystemObject
$folders = (Get-Childitem $path | ? {$_.Attributes -eq "Directory"})
foreach ($folder in $folders)
{
$folder | Add-Member -MemberType NoteProperty -Name "SizeMB" –Value(($FileSystemObject.GetFolder($folder.FullName).Size) / 1MB)
}
$folders | sort -Property SizeMB -Descending | select fullname,@{n=’Size MB’;e={"{0:N2}" –f $_.SizeMB}}
}

Categories
Tag Cloud
Blog RSS
Comments RSS
Last 50 Posts
Back
Void « Default
Life
Earth
Wind
Water
Fire
Light 
Pingback: Weekend Scripter: Sorting Folders by Size « LabRatCentral
Pingback: Weekend Scripter: Сортируем каталоги по размеру – Hey, Scripting Guy! Blog « sergey vasin