Select-String Examples: grep for PowerShell
If you know grep from Linux, Select-String is the same idea. It searches text for a pattern and returns the lines that match.
Search a file
Give it a path and a pattern. Patterns are regular expressions by default, and the search ignores case.
Select-String -Path server.log -Pattern 'timeout'
Search many files
Wildcards in the path let you search a whole folder. Add -Recurse through Get-ChildItem when you need subfolders.
Select-String -Path *.log -Pattern 'failed'
Get-ChildItem -Recurse -Filter *.log | Select-String 'failed'
Useful switches
-CaseSensitive matches exact case. -SimpleMatch treats the pattern as plain text, which helps when it contains dots or brackets. -NotMatch flips it and returns lines without the pattern. Pipe to Measure-Object to count.
Select-String -Path app.log -Pattern 'error' -CaseSensitive
Select-String -Path app.log -Pattern 'error' | Measure-Object
Practice it for real. shellreps has hands-on PowerShell labs that run in your browser, no install. The first one is free, no signup. The terminal mimics PowerShell syntax so the habits carry over, though it isn't Microsoft's PowerShell itself.