How it works...
The script may seem fairly long, and complicated. However, if you look at it piece by piece, there are four pieces to it. And here is how each of them works.
The first piece introduces you to searching for patterns in files. We already saw Select-String in Chapter 1, Introducing PowerShell Core, where we looked for a certain string within the Help documentation. That was when a certain string content was passed through the pipeline to Select-String. In this recipe, however, we leverage the file-handling capabilities of the cmdlet by passing the file path(s) as well as the pattern that we are looking for. Select-String returns the matches as an array, each element being the complete line that contains the pattern. In our case, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access