One of the batch scripts creates a logfile and it can have error messages like as below
Msg 2714, Level 16, State 1:
Server 'ABC', Procedure 'proc_test1', Line 189:
There is already an object named 'table_test' in the database.
Msg 207, Level 16, State 4:
Server 'ABC', Procedure 'proc_test2', Line 197:
Invalid column name 'employee'.
Msg 207, Level 16, State 4:
Server 'ABC', Procedure 'proc_test2', Line 197:
Invalid column name 'address'.
Using a powershell script to read and report errors to a mail from the log file. And i'm using this, which excludes certain warning messages too.
Select-String -Path 'C:\Users\BatchLog_20200911.txt' -Pattern "Msg","Error" | Select-String -Pattern "SQLState = S1000, NativeError = 0" -notmatch | select-object -Property Line,LineNumber
Output is as below
Line LineNumber
---- ----------
Msg 2714, Level 16, State 1: 2791
Msg 207, Level 16, State 4: 2794
Msg 207, Level 16, State 4: 2797
CT-LIBRARY error: 2828
ct_results(): network packet layer: internal net library error: Net-Library operation terminated due to disconnect 2829
"Errors encountered during execution. Exited with status: 596" 4168
So, it just prints line which match the query. I want to print the next lines which has actual error message description. Any advise here. Thanks.