Last active
August 29, 2015 14:25
-
-
Save sayedihashimi/26b96f73d3822b46317c to your computer and use it in GitHub Desktop.
PowerShell Measure-Directory function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Measure-Directory{ | |
| [cmdletbinding()] | |
| param( | |
| [Parameter(Position=0,ValueFromPipeline=$true)] | |
| [System.IO.DirectoryInfo[]]$path, | |
| [switch]$recurse | |
| ) | |
| process{ | |
| foreach($srcpath in $path){ | |
| $gciargs = @{ 'Path' = $srcpath } | |
| if($recurse){ | |
| $gciargs.Add('Recurse',$true) | |
| } | |
| $measure = Get-ChildItem @gciargs| Measure-Object -Property Length -Sum -Maximum -Minimum -Average | |
| New-Object -TypeName psobject -Property @{ | |
| NumFiles = $measure.Count | |
| TotalSize = $measure.Sum | |
| AverageFileSize = $measure.Average | |
| MaxFileSize = $measure.Maximum | |
| MinFileSize = $measure.Minimum | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment