PowerTip: Using PowerShell to Search Text Files for Letter Pattern

Summary: Use Windows PowerShell to search the contents of all text files in a folder for a specific letter pattern.

Hey, Scripting Guy! Question How can I use Windows PowerShell to search the contents of a lot of files in a folder for
           the occurrence of a specific letter pattern?

Hey, Scripting Guy! Answer Use the Select-String cmdlet, and specify the pattern and the path to the files.
           Windows PowerShell automatically reads the contents of the text files, and it will show the path
           and the line number of the file that contains the pattern. Here is an example that searches
           all text files in the c:\fso folder for the pattern gps:

Select-String -Pattern "gps" -Path c:\fso\*.txt

Comments (2)

  1. Jacob says:

    Googbox is capable of finding matching text inside thousands of files and get you the link to download it.
    Search can be done with regular expressions, include or exclude certain search patterns.
    http://www.googbox.com is capable of searching within folders and subfolders.
    Search is performed on the server, hence it will not affect your PC / Laptops performance.

  2. Brad_Voris says:

    Yes but that is a paid service. This is a script you can run against your own machine or on any server from your machine. Script at no cost and would be beneficial for the average home user 🙂

Skip to main content