Search Text With Select-String

Find lines matching a pattern across files, PowerShell's grep equivalent.

WindowssearchtextpowershellLow risk
Run Select-String -Path *.log -Pattern "error" to list matching lines.

01Command

Command
$ Select-String -Path *.log -Pattern "error"

02What it does

Select-String accepts a path or pipeline of files, a pattern (literal by default, regex with -Pattern), and returns match objects with file, line number and text. Combine with Get-ChildItem -Recurse to search an entire tree.

03Risk

RiskLow risk
RequirementsWindows 10/11 with PowerShell 5.1 or PowerShell 7+
!Warning: Patterns are treated as regular expressions by default, so characters such as . and * have special meaning; use -SimpleMatch for literal searches.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • Select-String
    Microsoft Learn · vendor-doc · 2026-09-20
    Evidence: Finds text and regular-expression matches in strings and files, like grep.

Last verified: 2026-09-20 · Category: Files & Folders

06Related solutions