Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-DirTreeInfo
- {
- <#
- Comment Based Help goes here ...
- #>
- [CmdletBinding ()]
- Param (
- [Parameter (
- Position = 0
- )]
- [string[]]
- $Path = $env:TEMP,
- [Parameter (
- Position = 1
- )]
- [int]
- $Depth = $Null
- )
- begin {}
- process
- {
- foreach ($Dir in $Path)
- {
- # this is _ugly_
- # the default is 256 errors and that fills up with nearly identical errors _quickly_
- # is there another way detect an error while continuing the Get-ChildItem call?
- $Error.Clear()
- $GCI_Params = @{
- LiteralPath = $Dir
- Recurse = $True
- Force = $True
- ErrorAction = 'SilentlyContinue'
- }
- if ($Depth -gt 0)
- {
- $GCI_Params.Add('Depth', $Depth)
- }
- $DirTree = Get-ChildItem @GCI_Params
- $DT_Stats = $DirTree.ForEach({$_.Length}) |
- Measure-Object -Sum -Maximum -Minimum
- $DirCount = $DirTree.Where({$_.PSIsContainer}).Count
- [PSCustomObject]@{
- StartingPath = $Dir
- Depth = ('_Unlimited_', $Depth)[$Depth -gt 0]
- ErrorCount = $Error.Count
- FirstErrorText = $Error[0].Exception.Message
- ObjectCount = $DirTree.Count
- DirCount = $DirCount
- FileCount = $DirTree.Count - $DirCount
- TotalSize_MB = [math]::Round($DT_Stats.Sum / 1MB, 2)
- FileSize_Min_MB = [math]::Round($DT_Stats.Minimum / 1MB, 2)
- FileSize_Max_MB = [math]::Round($DT_Stats.Maximum / 1MB, 2)
- }
- }
- }
- end {}
- } # end >> function Get-DirTreeInfo
Add Comment
Please, Sign In to add comment