[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [ValidateRange(1, 32767)] [int]$MinLength = 260, [string]$Csv ) $ErrorActionPreference = 'Stop' if (-not (Test-Path -LiteralPath $Path -PathType Container)) { throw "Folder not found: $Path" } $root = (Resolve-Path -LiteralPath $Path).Path $items = @( Get-ChildItem -LiteralPath $root -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.FullName.Length -ge $MinLength } | Sort-Object -Property { $_.FullName.Length } -Descending | Select-Object @{Name = 'Length'; Expression = { $_.FullName.Length } }, @{Name = 'Type'; Expression = { if ($_.PSIsContainer) { 'Directory' } else { 'File' } } }, FullName ) if ($items.Count -eq 0) { Write-Host "No paths found with length $MinLength or more." exit 0 } $items | Format-Table -AutoSize Write-Host "Found: $($items.Count)" if ($Csv) { $csvPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Csv) $items | Export-Csv -LiteralPath $csvPath -NoTypeInformation -Encoding UTF8 Write-Host "Report saved: $csvPath" }