Skip to main content

Command referenceSelect-String

Select-String command (Windows / PowerShell)

WindowsPowerShelltextbeginner

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 / optionMeaning
-PatternProvide one or more regular expressions.
-PathSelect files to search.
-SimpleMatchInterpret patterns as literal text.
-CaseSensitiveEnable case-sensitive matching.
-ContextInclude 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.

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.