|
param ( |
|
[Parameter(Mandatory = $true, ValueFromRemainingArguments = $true)] |
|
[string[]]$Paths |
|
) |
|
|
|
function Get-SizeReadable { |
|
param ([Int64]$bytes) |
|
$suffixes = "B","KB","MB","GB","TB","PB" |
|
$i = 0 |
|
while ($bytes -ge 1024 -and $i -lt $suffixes.Length - 1) { |
|
$bytes = [math]::Round($bytes / 1024, 2) |
|
$i++ |
|
} |
|
return "$bytes $($suffixes[$i])" |
|
} |
|
$dirs = @() |
|
$files = @() |
|
|
|
if ($Paths.Count -eq 1) { |
|
$Paths = @(Get-ChildItem -LiteralPath $Paths | Select-Object -ExpandProperty FullName) |
|
} |
|
|
|
foreach ($path in $Paths) { |
|
$item = Get-Item $path |
|
if ($item.PSIsContainer) { |
|
$dirs += $path |
|
} else { |
|
$files += $path |
|
} |
|
} |
|
Write-Host ("{0,-32} {1, -15} {2}" -f "Name", "Count", "Size") -ForegroundColor Green |
|
Write-Host ("{0,-32} {1, -15} {2}" -f "----", "-----", "----") -ForegroundColor Green |
|
foreach ($path in $dirs) { |
|
$item = Get-Item $path |
|
$stats = Get-ChildItem -Recurse -File -Path $path | Measure-Object -Property Length -Sum |
|
$sizeFormatted = Get-SizeReadable $stats.Sum |
|
$displayName = Split-Path -Path $path -Leaf |
|
|
|
if ($stats.Sum -ge 1073741824){ |
|
Write-Host ("{0,-32} {1, -15} {2}" -f $displayName, ("$($stats.Count) files"), $sizeFormatted) -ForegroundColor Red |
|
} else { |
|
Write-Host ("{0,-32} {1, -15} {2}" -f $displayName, ("$($stats.Count) files"), $sizeFormatted) -ForegroundColor Cyan |
|
} |
|
} |
|
foreach ($path in $files) { |
|
$item = Get-Item $path |
|
$sizeFormatted = Get-SizeReadable $item.Length |
|
$displayName = Split-Path -Path $path -Leaf |
|
|
|
if ($item.Length -ge 1073741824){ |
|
Write-Host ("{0,-32} {1, -15} {2}" -f $displayName, "", $sizeFormatted) -ForegroundColor Red |
|
} else { |
|
Write-Host ("{0,-32} {1, -15} {2}" -f $displayName, "", $sizeFormatted) -ForegroundColor Yellow |
|
} |
|
} |
|
Write-Host |