#requires -version 2.0 Param([string]$path="$env:userprofile\documents") if (Test-Path -path $path) { write-host "Collecting file information for $path" -ForegroundColor Green $files=dir $path -recurse -errorAction "SilentlyContinue" | where {-not $_.PSIsContainer} $stats=$files | Measure-Object -Property Length -sum $grouped=$files | group -property Extension foreach ($group in $grouped) { #measure the total size of each file type $measure=$group.group | measure-object -Property length -sum #calculate % of total size $perSize="{0:P4}" -f ($measure.sum/$stats.sum) #calculate % of total number $perTotal="{0:P4}" -f ($measure.count/$stats.count) #write a custom object to the pipeline new-object psobject -Property @{ Extension=$group.name Total=$group.count TotalSizeMB=[Math]::Round($measure.sum/1mb,2) PercentTotal=$perTotal PercentSize=$perSize Files=$group.group } } #foreach } #if test-path else { Write-Warning "Failed to find $path" }