Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-SubDirSize
- {
- [CmdletBinding ()]
- Param (
- [Parameter (
- Position = 0
- )]
- [string]
- $Path = $env:TEMP,
- [Parameter ()]
- [switch]
- $NoRecurse
- )
- begin {}
- process
- {
- $DirList = Get-ChildItem -LiteralPath $Path -Directory -ErrorAction SilentlyContinue
- foreach ($DL_Item in $DirList)
- {
- $GCI_Params = @{
- LiteralPath = $DL_Item.FullName
- Recurse = -not $NoRecurse
- File = $True
- Force = $True
- ErrorAction = 'SilentlyContinue'
- }
- $FileList = Get-ChildItem @GCI_Params
- if ($FileList.Count -gt 0)
- {
- $DirSize = [math]::Round(($FileList |
- Measure-Object -Property Length -Sum).Sum / 1MB, 2)
- }
- else
- {
- $DirSize = 0
- }
- [PSCustomObject]@{
- DirName = $DL_Item.FullName
- FileCount = $FileList.Count
- Size_MB = $DirSize
- }
- }
- }
- end {}
- } # end >>> function Get-SubDirSize
Add Comment
Please, Sign In to add comment