What's the DOS FINDSTR equivalent for PowerShell? I need to search a bunch of log files for "ERROR".
The Select-String cmdlet searches for text and text patterns in input strings and files. You can use it like Grep in UNIX and Findstr in Windows with Select-String in PowerShell. Select-String is based on lines of text.
Grep's core is simply the ability to search plain text for a RegEx pattern. Grep can search files in a given directory or streamed input to output matches. Did you know PowerShell has grep? Well.. almost.
To search for multiple matches in each file, we can sequence several Select-String calls: Get-ChildItem C:\Logs | where { $_ | Select-String -Pattern 'VendorEnquiry' } | where { $_ | Select-String -Pattern 'Failed' } | ...
The “$_” is said to be the pipeline variable in PowerShell. The “$_” variable is an alias to PowerShell's automatic variable named “$PSItem“. It has multiple use cases such as filtering an item or referring to any specific object.
Here's the quick answer
Get-ChildItem -Recurse -Include *.log | select-string ERROR
I found it here which has a great indepth answer!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With