[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [ValidateRange(1, 200)] [int]$Top = 10, [string]$Csv ) $ErrorActionPreference = 'Stop' $resolved = Resolve-Path -LiteralPath $Path -ErrorAction Stop if (-not (Test-Path -LiteralPath $resolved -PathType Container)) { throw "Укажите папку: $resolved" } $files = @(Get-ChildItem -LiteralPath $resolved -File -Recurse -ErrorAction SilentlyContinue) if ($files.Count -eq 0) { Write-Host 'Файлы не найдены.' exit 0 } $groups = $files | Group-Object { if ($_.Extension) { $_.Extension.ToLower() } else { '(none)' } } | ForEach-Object { $size = ($_.Group | Measure-Object -Property Length -Sum).Sum [pscustomobject]@{ Extension = $_.Name Count = $_.Count SizeMB = [math]::Round($size / 1MB, 2) } } | Sort-Object SizeMB -Descending $totalBytes = ($files | Measure-Object -Property Length -Sum).Sum $groups | Format-Table -AutoSize Write-Host ("Всего файлов: {0}, объём: {1:N2} GB" -f $files.Count, ($totalBytes / 1GB)) Write-Host "Крупнейшие файлы:" $files | Sort-Object Length -Descending | Select-Object -First $Top | Select-Object @{Name = 'SizeMB'; Expression = { [math]::Round($_.Length / 1MB, 2) } }, @{Name = 'Modified'; Expression = { $_.LastWriteTime.ToString('yyyy-MM-dd') } }, FullName | Format-Table -AutoSize if ($Csv) { $groups | Export-Csv -LiteralPath $Csv -NoTypeInformation -Encoding UTF8 Write-Host "Отчёт сохранён: $Csv" }