We help IT Professionals succeed at work.
Get Started

Powershell Scan Event log

95 Views
Last Modified: 2016-04-05
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.
Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE