Function Get-DirTotalFileSize() { if ($args.Length -ne 1) { $Host.UI.WriteErrorLine("Usage: Get-DirectorySize ") return } $pathto = $args[0] if (!(Test-Path -PathType Container $pathto)) { $Host.UI.WriteErrorLine("Cannot access $pathto : No such directory") return } $o = @() $dirs = Get-ChildItem $pathto | Where-Object PSisContainer $dirs | % { $PATH=$_; if ((Get-ChildItem $_.FullName).Length -ne 0) { $measure = Get-ChildItem -Force -Recurse $_.FullName | Measure-Object -Sum Length $o += [PSCustomObject]@{ PATH=$PATH.FullName; SUM=$measure.Sum } } else { $o += [PSCustomObject]@{ PATH=$PATH.FullName; SUM=0 } } } $o }