liveBook · Manning

MatchInfo

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

A MatchInfo object is a PowerShell object representing a text match found by Select-String, including information such as the path, line number, and matching line.

A MatchInfo object is the result produced by Select-String when text matches a pattern. It carries useful match details, including the filename, line number, and matching line. section 21.4

Finding HTTP 400-series errors

Search recursively through .log files with a regular expression, then format each MatchInfo result as a table showing Filename, LineNumber, and Line. The formatted results can be redirected to a file for web developers. section 21.4

PS C:\logfiles> get-childitem -filter *.log -recurse | 
 select-string -pattern "\s40[0-9]\s" | 
 format-table Filename,LineNumber,Line -wrap

Inspect a practical pipeline that creates MatchInfo objects with Select-String and formats their key properties. section 21.4

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

How deep it goes
Defines the result object and demonstrates selected properties, but does not detail its full object model.
Examples
Demonstrates matching HTTP 400-series error codes and Gecko-based browser user-agent strings in log files.
What it assumes
Assumes familiarity with Select-String patterns, regular expressions, pipelines, and basic PowerShell commands.
What you can do after
Apply Select-String and Format-Table to produce readable match reports containing filenames, line numbers, and matching lines.
How it connects
Connects MatchInfo with Select-String, regular expressions, pipelines, and Format-Table.

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.