Skip to content

Instantly share code, notes, and snippets.

@RhysC
Created July 18, 2011 20:00
Show Gist options
  • Save RhysC/1090497 to your computer and use it in GitHub Desktop.
Save RhysC/1090497 to your computer and use it in GitHub Desktop.
Get all the immediate children folders and tell me their total size
function Get-ChildFolderTotalSize
{
param($parentDir)
$children = (Get-ChildItem $parentDir | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)
$results = @();
foreach ($i in $children)
{
$childSum = (Get-ChildItem $i.FullName -recurse | Measure-Object -property length -sum)
$results += New-Object Object |
Add-Member NoteProperty FullName $i.FullName -PassThru |
Add-Member NoteProperty Name $i.Name -PassThru |
Add-Member NoteProperty TotalSizeInMB ($childSum.sum / 1MB) -PassThru;
}
$children = (Get-ChildItem $parentDir | Measure-Object -property length -sum)
"$parentDir -- " + "{0:N2}" -f ($children.sum / 1MB) + " MB"
$results |
Format-Table Name, @{ Label="Total folder Size"; Expression={"{0:N2}" -f $_.TotalSizeInMB + " MB"}; Alignment="Right"}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment