[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [switch]$Recurse, [string]$Csv ) $ErrorActionPreference = 'Stop' if (-not (Test-Path -LiteralPath $Path -PathType Container)) { throw "Folder not found: $Path" } $root = (Resolve-Path -LiteralPath $Path).Path $pattern = '[\[\]#%&${}''"!@+;=]' if ($Recurse) { $items = @(Get-ChildItem -LiteralPath $root -File -Recurse -ErrorAction SilentlyContinue) } else { $items = @(Get-ChildItem -LiteralPath $root -File -ErrorAction SilentlyContinue) } $rows = @() foreach ($file in $items) { $found = @([regex]::Matches($file.Name, $pattern) | ForEach-Object { $_.Value } | Select-Object -Unique) if ($found.Count -gt 0) { $rows += [pscustomobject]@{ Name = $file.Name Characters = ($found -join ' ') FullName = $file.FullName } } } if ($rows.Count -eq 0) { Write-Host 'No files with special characters found.' exit 0 } $rows | Format-Table -AutoSize Write-Host "Found: $($rows.Count)" if ($Csv) { $csvPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Csv) $rows | Export-Csv -LiteralPath $csvPath -NoTypeInformation -Encoding UTF8 Write-Host "Report saved: $csvPath" }