I want a script that looks for a particular string pattern or patterns in a given directory and started with the following:
Set-location C:\Users\thchen\Desktop\dprogs Get-ChildItem -Recurse | Select-String -Pattern ':\' -SimpleMatch | group path | select name | Export-Csv -Path C:\Users\thchen\Desktop\TestMultiPattern.csv -Encoding ASCII -NoTypeInformation
The script above works beautifully without problem. When I open the csv file, cell A1 contains the word ‘Name’ and the rest of column A contains all the files under C:\Users\thchen\Desktop\dprogs containing the text pattern ':'. However, I am looking for more than one string pattern. I want a list of all files that contains either ':' or ‘\’. So I modified my code to
Get-ChildItem -Recurse -File | where {($_.FullName | Select-String -Pattern (':\') -SimpleMatch) -or ($_.FullName | Select-String -Pattern ('\\') -SimpleMatch)} | group path | select name | Export-Csv -Path C:\Users\thchen\Desktop\Output3.csv -Encoding ASCII -NoTypeInformation
Now when open the output csv file, all it contains is the word ‘Name’ in cell A1 and the rest of column A are empty. Can anybody see what I might have done wrong? Thanks for any help.