We help IT Professionals succeed at work.

powershell filter/match help

rutgermons
rutgermons asked
on
folks

my powershell script searches for a specific value  i.e. ERROR in another log file

Get-Content TEST.log -wait | where { $_ -match “Error” } |out-file logger.txt -append

how can i get it to search multiple values? i.e  ERROR and INCIDENT

keen for your thoughts
Comment
Watch Question

Senior Network Systems Specialist
Commented:
Try this where you can use condition functions such as -not, -and and -or:

Get-Content TEST.log -wait | where { $_ -match "Error"  -or $_ -match "Incident"} |out-file logger.txt -append
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
It's usually better to use the regex features of -match. But in the case of simple string pattern matches only, I would use the Select-String cmdlet:
Get-Content TEST.log -wait | Select-String -SimpleMatch “Error”, "Incident" |out-file logger.txt -append

Open in new window