Powershell select-string not finding ÿ

Viewed 166

I've got a log file with some bad characters in it. While there are many, the one I'm specifically interested in at the moment is ÿ

When I try to do a simple select-string with it, I get no results at all:

select-string -path D:\logs\*.log -Pattern 'ÿ'

I have tried adding encoding, but that didn't return any results either. I tried all of the following:

select-string -path D:\logs\*.log -Pattern 'ÿ' -Encoding "Unicode"
select-string -path D:\logs\*.log -Pattern 'ÿ' -Encoding "UTF8"
select-string -path D:\logs\*.log -Pattern 'ÿ' -Encoding "ASCII"

What am I missing?

1 Answers

Try to use a regex with a negative lookahead. I think this is the easiest way since we don't know much about the file or the character encoding.

-pattern '^(?!.*[a-zA-Z]|\S\s|^$).*$'

This will search for anything that is not: a thru z lowercase, A thru Z uppercase, digits, or whitespace like a space or new line. In theory it should capture your "ÿ" character and any other weirdo characters that may be showing up. You can add more to it if you need to. | symbols means "AND" so you can add a "|" after the $ in the pattern and add more characters if necessary like ^(?!.*[a-zA-Z]|\S\s|^$).*$|\=

Related