Last active
October 1, 2021 16:40
-
-
Save konung/ad47cf347ba24df3912f1385ca99b9ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Path = 'i:\' | |
$OutCSV = 'c:\Windows\Temp\i_drive_suspects.csv' | |
$RegEx = "[^-\w\.\ \~\'\(\)\$\&\+\,\@\%]" # This matches anything that isn't a-z, A-Z, 0-9, or the '-', '_', and '.' characters. Add any others you need to permit. | |
$Output = Get-ChildItem -Path $Path -Recurse | Where-Object -FilterScript { $_.Name -match $RegEx } | ForEach-Object { | |
$out = [PSCustomObject]@{ # Note: add any additional inforamtion you want to caputure here | |
Name = $_.Name | |
FullPath = $Path | |
Path = (Split-Path -Path $_.FullName) | |
Type = $_.GetType().Name.Replace('Info', '') | |
} | |
Write-Output $out | |
} | |
$Output | Export-Csv -Path $OutCSV -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://community.spiceworks.com/topic/2030534-powershell-find-files-with-illegal-characters-and-export-list-to-csv for original