liveBook · Manning

Select-String

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

Select-String is a PowerShell cmdlet that searches text for matches to specified strings or regular expressions.

Select-String searches text for literal strings or regular-expression patterns. It can scan many log files, return matching lines, and produce MatchInfo objects containing details such as the filename and line number. section 21.4

A practical log-search workflow is:

  • Use Get-ChildItem with a *.log filter and recursion to gather files from a log directory. section 21.4
  • Pipe the files to Select-String with a pattern such as "\s40[0-9]\s" to find HTTP errors from 400 through 409 without matching filenames such as error401.html. section 21.4
  • Pipe results to Format-Table Filename, LineNumber, Line -wrap for a cleaner, wrapped display; the output can also be redirected to developers. section 21.4

Finding Gecko browser requests

Search recursively with Select-String -pattern "10\.0;[\w\W]+\+Gecko". The escaped period matches a literal period, [\w\W]+ matches any characters, and \+Gecko identifies the browser marker. section 21.4

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Demonstrates pipelines, regex construction, MatchInfo fields, and formatted output without exploring cmdlet internals.
Examples
Uses 400-series HTTP errors, Gecko user-agent strings, and Security event 4624 messages as search targets.
What you can do after
Diagnose log patterns with Select-String and present matching filenames, line numbers, and lines for further review.
How it connects
Connects regular expressions with Get-ChildItem, Format-Table, pipelines, IIS-style logs, and event-log messages.

Also explained in

Compare how 2 books explain Select-String →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.