Grep on Windows: Select-String
Search inside text files and logs with regex, returning file, line number and match.
01Command
$ 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
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Select-String (Microsoft.PowerShell.Utility)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
Built-in PowerShell comparison that lists lines unique to each file.
Create or update a .zip from any files or folder contents straight from PowerShell.
A built-in PowerShell one-liner that answers 'is port 5432/3389/443 actually open through this network?' — no telnet client needed.