Search Text With Select-String
Find lines matching a pattern across files, PowerShell's grep equivalent.
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
!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-StringEvidence: Finds text and regular-expression matches in strings and files, like grep.
Last verified: 2026-09-20 · Category: Files & Folders
06Related solutions
Grep on Windows: Select-String
Search inside text files and logs with regex, returning file, line number and match.
Diff Two Text Files with Compare-Object
Built-in PowerShell comparison that lists lines unique to each file.
Zip Files with Compress-Archive
Create or update a .zip from any files or folder contents straight from PowerShell.