[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [ValidateRange(10, 10000)] [int]$MaxLength = 120, [ValidateRange(0, 100000)] [int]$Top = 0, [switch]$Recurse, [string]$Csv ) $ErrorActionPreference = 'Stop' $item = Get-Item -LiteralPath $Path -ErrorAction Stop if ($item.PSIsContainer) { $files = Get-ChildItem -LiteralPath $item.FullName -File -Recurse:$Recurse -ErrorAction SilentlyContinue } else { $files = @($item) } $results = New-Object System.Collections.Generic.List[object] foreach ($file in $files) { $lineNumber = 0 try { $lines = Get-Content -LiteralPath $file.FullName -Encoding UTF8 -ErrorAction Stop } catch { Write-Warning "Пропуск $($file.FullName): $($_.Exception.Message)" continue } foreach ($line in $lines) { $lineNumber++ if ($line.Length -le $MaxLength) { continue } $preview = $line.Trim() if ($preview.Length -gt 80) { $preview = $preview.Substring(0, 77) + '...' } $results.Add([pscustomobject]@{ File = $file.FullName Line = $lineNumber Length = $line.Length Preview = $preview }) } } if ($results.Count -eq 0) { Write-Host 'Длинные строки не найдены.' exit 0 } $output = $results if ($Top -gt 0) { $output = $results | Sort-Object Length -Descending | Select-Object -First $Top } $output | Format-Table -AutoSize -Wrap if ($Csv) { $output | Export-Csv -LiteralPath $Csv -NoTypeInformation -Encoding UTF8 Write-Host "Отчёт сохранён: $Csv" }