PowerTip: Use PowerShell to Parse Text Files


Summary: Quickly search files for text with Windows PowerShell.

Hey, Scripting Guy! Question How can I use Windows PowerShell to quickly search text files for a string?

Hey, Scripting Guy! Answer Use the Select-String cmdlet and supply a path and a pattern.
          In the following example, I search the current folder for the computer name dc13:

Select-String -Path *.txt -Pattern 'dc13'

Comments (3)

  1. Doug says:

    How about Word files? What's the trick to searching them for a string?

  2. Magnus says:

    Good question, Doug. Hope someone can help.

  3. jrv says:

    @Doug, @Magnus

    Windows Desktop Search searches inside of Office files because it has extensions that allow it to index formatted files.  The PowerShell "Select-String" CmdLet searches only in text files.  Word files are NOT text files.

    If you do not have Desktop Search installed or want to script this you need to open each file and use the Word search API.

Skip to main content