In Windows How Do You Search the Contents of Files in a Folder and Recursively the Files in the Folder’s Subdirectories for a Specific Pattern?

Problem scenario
You want to find an .html, .txt, or .rtf file that has the pattern "cool" in it.  You do not need to search for .doc or .docx files. How do you write a PowerShell command to search the contents of files and subdirectories of a given folder to see if they have a text string that matches the word "cool"?

Solution
Run these two commands:

cd c:\to\the\folder\you\want\

Get-ChildItem -recurse | Select-String -pattern "cool"

Leave a comment

Your email address will not be published. Required fields are marked *