<# .SYNOPSIS Determine human readable filesize .LINK https://stackoverflow.com/questions/24616806/powershell-display-files-size-as-kb-mb-or-gb #> # Get-Help wont work if script starts with function... Write-Host "`n" (Get-Help $PSCommandPath).synopsis function DisplayInBytes($num) { $suffix = "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" $index = 0 while ($num -gt 1kb) { $num = $num / 1kb $index++ } "{0:N1} {1}" -f $num, $suffix[$index] } Write-Host Directory Information -fore Magenta $files = Get-ChildItem -Recurse $bytes = ($files | Measure-Object -Property Length -Sum).Sum $hash = [ordered]@{ Filecount = $files.count WorkingDir = $PWD } $hash | Format-Table -HideTableHeaders Write-Host Static Measurements -fore Magenta $hash = [ordered]@{ Bytes = $bytes Kilobytes = ("{0} KB" -f ($bytes / 1KB)) Megabytes = ("{0} MB" -f ($bytes / 1MB)) Gigabytes = ("{0} GB" -f ($bytes / 1GB)) Terabytes = ("{0} TB" -f ($bytes / 1TB)) } $hash | Format-Table -HideTableHeaders Write-Host Dynamic Measurements -fore Magenta $hash = [ordered]@{ Bytes = $bytes Truncated = $(DisplayInBytes $bytes) } $hash | Format-Table -HideTableHeaders