Avatar of Leo Torres
Leo Torres
Flag for United States of America

asked on 

Powershell Scan Event log

Hello,

CLS
$a = Get-Date
$b = $a.AddHours(-1) #$a.AddDays(-1)

$Server = "ServerName"

Get-EventLog -ComputerName $Server -LogName Application -After $b -Before $a -Source "MSSQLSERVER" | ?{$_.EventID -eq 14151 } 

Open in new window


The code above returns
   Index Time          EntryType   Source                 InstanceID Message                                                                                    
   ----- ----          ---------   ------                 ---------- -------                                                                                    
 2255302 Mar 22 10:39  Error       MSSQLSERVER            3221239623 The description for Event ID '-1073727673' in Source 'MSSQLSERVER' cannot be found.  The...
 2255299 Mar 22 10:38  Error       MSSQLSERVER            3221239623 The description for Event ID '-1073727673' in Source 'MSSQLSERVER' cannot be found.  The...
 2255298 Mar 22 10:38  Error       MSSQLSERVER            3221239623 The description for Event ID '-1073727673' in Source 'MSSQLSERVER' cannot be found.  The...
 2255297 Mar 22 10:38  Error       MSSQLSERVER            3221239623 The description for Event ID '-1073727673' in Source 'MSSQLSERVER' cannot be found.  The...
 2255296 Mar 22 10:37  Error       MSSQLSERVER            3221239623 The description for Event ID '-1073727673' in Source 'MSSQLSERVER' cannot be found.  The...
 2255295 Mar 22 10:37  Error       MSSQLSERVER            3221239623 The description for Event ID '-1073727673' in Source 'MSSQLSERVER' cannot be found.  The...
 2255294 Mar 22 10:37  Error       MSSQLSERVER            3221239623 The description for Event ID '-1073727673' in Source 'MSSQLSERVER' cannot be found.  The...

Open in new window



I need this script to go back 1 hour and check for error.  If it returns at least 1 error send me an email with the time and message in the body as a table. But I cant even get the message to display correctly.
PowershellScripting Languages

Avatar of undefined
Last Comment
footech

8/22/2022 - Mon