I have found several resources that use the following script to get folder sizes
$colItems = (Get-ChildItem $startFolder -recurse | Where-Object {$_.PSIsContaine
The solution posted by @Linga:
"Get-ChildItem -Recurse 'directory_path' | Measure-Object -Property Length -Sum"
is nice and short. However, it only computes the size of 'directory_path'
, without sub-directories.
Here is a simple solution for listing all sub-directory sizes. With a little pretty-printing added.
(Note: use the -File
option to avoid errors for empty sub-directories)
foreach ($d in gci -Directory -Force) {
'{0:N0}' -f ((gci $d -File -Recurse -Force | measure length -sum).sum) + "`t`t$d"
}