Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This command lines works running in cmd.exe:

findstr /l /i /s /c:"key=\"Smtp" *.config

However running in PowerShell 2 on Windows 7 Ultimate x64, findstr seems to freeze no matter which combination I use. I am searching a toy file I created (only one in folder) that has only this entry in it, so I know it's not just taking longer:

<add key="SmtpHost" value="localhost">

But these variations I tried never return in PowerShell (they also don't give the >> prompt to indicate an unterminated string).

findstr /l /i /s /c:"key=`"Smtp" *.config
findstr /l /i /s /c:"`"" *.config
findstr /l /i /s /c:"key=""Smtp" *.config
findstr /l /i /s /c:'key="Smtp' *.config

When I change it to use regular expressions, with a wild card, it will work:

findstr /r /i /s /c:"key=.Smtp" *.config

But how do I pass a double quote to findstr in PowerShell successfully?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Try this:

findstr /l /i /s /c:"key=\`"Smtp" *.config

you need to escape from both posh and \"`

more info here: http://www.rlmueller.net/PowerShellEscape.htm

share|improve this answer
add comment

Is there some functionality that you are getting from Findstr that you can't get from the Powershell cmdlets themselves?

Get-ChildItem .\* -Include *.config -Recurse | Select-String '"key="Smtp"'
share|improve this answer
1  
That's a great meta-answer; removing the need for my original answer, and I'll probably use it (if I can figure out how to alias it into something nice). Still nice to know the literal answer, in case it ever comes up in another tool that PS can't so easily replace. –  ZeroBugBounce Aug 18 '11 at 5:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.