powershell filter/match help


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
Who is Participating?
Peter HutchisonSenior Network Systems SpecialistCommented:
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
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.