/build/static/layout/Breadcrumb_cap_w.png

Searching string with "\" charachter in powershell

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?

1 Comment   [ + ] Show comment
  • Boom indeed! Many thanks kind sir. That did it. - TonyFishers 7 years ago

Answers (1)

Answer Summary:
Posted by: rileyz 7 years ago
Red Belt
0

Top Answer

Try \

-Pattern 'cygdrive\\c'

Btw use single quotes, only use double quotes when you need to expand vars etc.

BOOM!
Err, celebrating early, but it should fix your issue.

RegEx is like reading the Matrix :S

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:

Share

 
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