2

I am parsing error log files across multiple servers and need to report on problem errors. The error log files should contain at least the following (known errors that are OK):

  • ERROR Some error text
  • ERROR Some more error text
  • ERROR Here is more error text

What I need is a Select-String search pattern that includes all three text strings above:

$Search_Str_1 = "ERROR Some error text"
$Search_Str_2 = "ERROR Some more error text"
$Search_Str_3 = "ERROR Here is more error text"

$Search_Str_1, $Search_Str_2, and $Search_Str_3 are acceptable error strings and should not be reported if found in the error logs. However, if any additional error string is found that does not match any of the above search strings, then it should be reported as a bad error.

Example:

  • ERROR Some error text
  • ERROR Some more error text
  • ERROR Here is more error text
  • ERROR This is bad error text and should be reported

The 4th error line (and any other line that does not match search_str 1, 2, or 3) would need to be reported as bad.

Hypothetical code:

$ErrorLog = Get-ChildItem -Path $LOG_PATH -Include Error.log -Recurse | Select-String -notmatch ($Search_Str_1 -or $Search_Str_2 -or $Search_Str_3)

How would I do this?

2 Answers 2

8

select-string -pattern takes in an array. Put those search string in an array and pass it to the select string. Add the -NotMatch flag if you want it to not match the patterns you passed in.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, manojlds! Putting the search strings in an array worked!!
0

select-string, alias sls, will take a comma seperated list of patterns. Knowing this you can just:

sls 'pattern1','pattern2',...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.