PowerTip: Use PowerShell to Parse Text Files

PowerTip: Use PowerShell to Parse Text Files

  • Comments 3
  • Likes

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'

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • How about Word files? What's the trick to searching them for a string?

  • Good question, Doug. Hope someone can help.

  • @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.