Searching string with "\" charachter in powershell
10/27/2016 475 views
Dear all ,
Hope you are well. I need to comb through a bunch of folders containing config files and find all files that contain a reference of specific string that has "\" in it using powershell. This is what am running ...
Get-ChildItem -Path d:\config -recurse | Select-String -Pattern "cygdrive\c"| Export-Csv D:\otests.csv
I get this error message :
Select-String : parsing "cygdrive\c" - Missing control character.
At line:1 char:68
+ Get-ChildItem -Path d:\config -recurse | Select-String <<<< -Pattern "cygdrive\c"| Export-Csv D:\results.csv
+ CategoryInfo : NotSpecified: (:) [Select-String], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.SelectStringCommand
Now I am aware of escape charachters in powershell , however I think for this I need to use regex command which am not at all familiar with. Can anyone please advise?
Answer Chosen by the Author
Please log in to answer
Btw use single quotes, only use double quotes when you need to expand vars etc.
Err, celebrating early, but it should fix your issue.
RegEx is like reading the Matrix :S
Answered 10/27/2016 by: rileyz