Windows – How to escape double quote character for use in findstr on the PowerShell command line

command-line-interfacefindstrpowershellwindows

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?

Best Answer

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