
Adding this parameter modifies the emitted MatchInfo object to include a new Context property that contains the lines specified. Context – A very useful parameter in that, you can define the number of lines before and after the match that will be displayed.CaseSensitive – Matches are not case-sensitive by default, this forces the cmdlet to look for matches that match exactly to the input pattern.A single MatchInfo object will still be emitted for each line, but it will contain all of the matches found. AllMatches – Normally, Select-String will only look for the first match in each line, using this parameter the cmdlet will search for more than one match.If the BOM is missing, Select-String will assume it is a UTF8 file. Additionally, Select-String can work with different file encodings, such as Unicode text, by use the byte-order-mark (BOM) to determine the encoding format.

Select-String (our PowerShell grep) works on lines of text and by default will looks for the first match in each line and then displays the file name, line number, and the text within the matched line. Therefore what built-in abilities exist to search for plain text using RegEx patterns much like grep does? In this article we explore the myriad ways to search for text in files using PowerShell. PowerShell, being a language, is more than just a single purpose binary. Did you know PowerShell has grep? Well.almost.

Grep can search files in a given directory or streamed input to output matches. Grep’s core is simply the ability to search plain text for a RegEx pattern. This venerable tool has been around for decades and is crucial to any administrator’s toolbelt.

One of the first Linux commands that many system administrators learn is grep.
