Grep on Windows: Select-String

Search inside text files and logs with regex, returning file, line number and match.

WindowssearchtextpowershellLow risk
Run `Select-String -Path "*.log" -Pattern "error"` to print each matching line with its filename and line number.

01Command

Command
$ Select-String -Path "$env:USERPROFILE\Documents\*.log" -Pattern "error"

02What it does

Select-String is PowerShell's grep: it accepts wildcards in -Path, treats -Pattern as a regular expression by default (use -SimpleMatch for literal text), and outputs objects carrying Filename, LineNumber and Line. Combine with Get-ChildItem -Recurse via the pipeline to search a whole tree: `gci -Recurse *.txt | Select-String pattern`. Remember that matches are case-insensitive unless you add -CaseSensitive.

03Risk

RiskLow risk

04Undo

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

05Sources

  • Select-String (Microsoft.PowerShell.Utility)
    Microsoft Learn · vendor-doc · 2026-09-17
    Evidence: Documents Select-String with -Path, -Pattern (regex), -CaseSensitive and -SimpleMatch parameters for searching file content.

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

06Related solutions