3

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?

ZeroBugBounce
  • 133
  • 1
  • 1
  • 4

2 Answers2

2

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

Jason Horner
  • 612
  • 2
  • 6
  • 13
2

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"'
EBGreen
  • 1,443
  • 11
  • 10
  • 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 05:19