Get-FolderSize.psm1
function Get-FolderSize { param( [Parameter(Mandatory=$true, ValueFromPipeline=$true)] [string]$Path, [Parameter(Mandatory=$false, ValueFromPipeline=$false)] [int]$Depth = 5 ) $array = @() $i=0 Write-Host "Retriving Folder in $path" -ForegroundColor Cyan $listdir = Get-ChildItem -Directory -Path $path -Recurse -Depth 5 -ErrorAction SilentlyContinue | select FullName | % {$_ -replace("@{FullName=","") -replace("}","")} foreach($dir in $listdir) { $tot = $listdir.Count $i++ $per = [math]::Round(($i*100)/$tot) Write-Progress -Activity "Calculating Folder Size" -Status "$per`% Calculating: $dir" -PercentComplete $per $size = Get-ChildItem -Path $dir -Recurse -ErrorAction SilentlyContinue | Measure-Object -Property Length -sum -ErrorAction SilentlyContinue | select Sum | % {$_ -replace("@{Sum=","") -replace("}","")} [int]$gb = [math]::Round($size / 1GB) $array += [pscustomobject]@{Path="$dir";Gb=$gb} } Write-Progress -Activity "Calculating Folder Size" -Completed return $array } Export-ModuleMember -Function Get-FolderSize |