


In a regular expression, those parentheses create a capture group.īy surrounding a search term with parentheses, PowerShell is creating a capture group. This pattern contains a set of parenthesis. In the previous example, notice the regex pattern used ( This (is)). The properties of a select-string operation Using Capture Groups To do that, provide a regex pattern using the Pattern parameter and the path to the text file using the Path parameter. Since the pattern you’re looking for is in a file, you’ll first need to read that file and then look for a regex match.

Related: How to use PowerShell’s Grep (Select-String) Select-String is a PowerShell cmdlet that allows you to provide a regular expression pattern and return a string that matches that pattern. In this situation, Select-String is going to be your new favorite tool. This serial number is located on the SerialNumber= line. In this instance, let’s say that you need to extract the serial number of this computer.
