Command referenceSelect-String
Select-String command (Windows / PowerShell)
What it does
Search strings and files with .NET regular expressions. Guides covering the select-string powershell usually need pipeline-friendly examples, common parameters, and how the cmdlet compares with classic CMD or Linux tools. This page includes syntax, options, and copyable PowerShell examples.
Search strings and files with .NET regular expressions.
Syntax
Select-String [-Pattern] <String[]> [-Path] <String[]> [-SimpleMatch] [-CaseSensitive] [-Context <Int32[]>]
Common options
| Flag / option | Meaning |
|---|---|
| -Pattern | Provide one or more regular expressions. |
| -Path | Select files to search. |
| -SimpleMatch | Interpret patterns as literal text. |
| -CaseSensitive | Enable case-sensitive matching. |
| -Context | Include lines before and after matches. |
Practical examples
Search log
Select-String -Path .\app.log -Pattern 'error|fatal'
Returns matching lines and metadata.
Literal search
Select-String *.txt -SimpleMatch 'total [USD]'
Avoids treating brackets as regex syntax.
Pipeline search
Get-Process | Out-String -Stream | Select-String 'node'
Searches a textual process rendering.
Linux ↔ Windows equivalent
Closest match: grep (Linux / bash / sh / zsh). Search text for lines matching a pattern.
Common mistakes
- Forgetting patterns are regular expressions by default.
- Converting rich objects to text when Where-Object could filter properties directly.
Related commands
- Get-ContentRead file content or provider data as a stream of objects.
- Where-ObjectFilter pipeline objects by property values or a script block predicate.
- findstrSearch files or piped text using literal strings or regular expressions.
- grepSearch text for lines matching a pattern.
- catConcatenate files and write their contents to standard output.
- echoWrite arguments and shell-expanded values to standard output.
- echoDisplay text or control command echoing in a batch script.
- tailPrint the end of input and optionally follow appended data.
FAQ
What does Select-String do in PowerShell?
Search strings and files with .NET regular expressions.
How can I see examples for Select-String?
Run `Get-Help Select-String -Examples`, then adapt an example to the provider and objects you are using.
What is a practical Select-String example?
Try `Select-String -Path .\app.log -Pattern 'error|fatal'` — Returns matching lines and metadata.
Does Select-String return text or objects?
Select-String normally participates in PowerShell's object pipeline; formatting seen in the console is a view of those objects.
Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.