Scripting Question

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 Summary:
1 Comment   [ + ] Show comment


  • Boom indeed! Many thanks kind sir. That did it.

Answer Chosen by the Author

Try \

-Pattern 'cygdrive\\c'

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
Red Belt

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ