How to “grep” for multiple strings in files on Windows with PowerShell.

February 25, 2015

So you want to search for multiple strings in your files on Windows?

Sure, you can do the job several ways, but if you have PowerShell installed on your box, you might use this snippet :

get-childitem "folder_where_to_look" -include *.txt -rec | where { $_ | Select-String -Pattern ‘find_me_1’ } | where { $_ | Select-String -Pattern ‘find_me_2’ }

Basically what this snippet does this :

  • find all .txt files in supplied folder and recursively in all subfolders, pass this list to
  • first pattern search for “find_me_1 string, than pass list of matching files with this string to
  • second pattern search
  • pass result to console

Nice this is, that you can also use RegEx in patterns that will be searched for and you can also dump found files to file for later use.

Hope this helps.


Profile picture

Written by Dušan Roštár - the "mr edge case" guy
my twitter : rostacik, my linkedin : rostar, drop me an email : here