Getting a Folder Tree Size with PowerShell

PowerShell is a Windows System Admins swiss army knife and there seems to be no limit to the things you can accomplish with it!

It is particularly easy to get the size of a set of folders (e.g. folders within a folder tree) using PowerShell. This is accomplished by getting the total contents size of each directory recursively to an output


$colItems = Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $true} | Sort-Object
foreach ($i in $colItems)
    $subFolderItems = Get-ChildItem $i.FullName -recurse -force | Where-Object {$_.PSIsContainer -eq $false} | Measure-Object -property Length -sum | Select-Object Sum
    $i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1MB) + " MB"

Note: This will not include results for any items whic you don’t have read access to.