Search for String of text from specific file types

I have a PS question and forgive me as I am relatively new to PS. If I wanted to utilize PS to search a system for all files with a specific file type such as *.text as an example and search those files for a specific string of characters and pull any “True” or “False” statements for if the strings were found within each file located. What would be the best way to accomplish this.

Get-ChildItem und Select-String are your friends. You should carefully read the help including the examples and you’re almost done. :wink:

ls -r *.txt | select-string foobar

If you want to just display files under a certain path (recursively), and show only the files that match without including duplicates, then something like this will should work for you. The reason for the “Sort-Object -Unique” part has to do with matching multiple lines in the same file.

#Simple Example
$FileType = '*.ps1'
$SearchPath = './'
$SearchPattern = 'function'
Get-ChildItem -Include $FileType -Recurse -Path $SearchPath | Select-String -Pattern $SearchPattern | Sort-Object -Unique -Property Path | Select-Object Path

Really, this would be better served as a function or advanced function, especially if you truly need to know which files return ‘False’ since they do not contain the pattern. I’m not sure what your exact use case is, but conceptually, you may want to start and experiment with this pattern. If this falls short, then post how it does and someone may be able to help.