Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use powershell to alert me when an error occurs in the event viewer on my new Win2k12 Standard Server, I was thinking I could have the script execute every 10mins but don't want to put any strain on the server just for event log checking, here is the powershell script I want to use:

$SystemErrors = Get-EventLog System | Where-Object { $_.EntryType -eq "Error" }
If ($SystemErrors.Length -gt 0) {
  Send-MailMessage -To "" -From $env:COMPUTERNAME +" -Subject $env:COMPUTERNAME + " System Errors" -SmtpServer "" -Priority High

What is a safe frequency I can run this script at without hurting my server?


Intel Xeon E5410 @ 2.33GHz x2
3x 7200RPM S-ATA 1TB (2x RAID1)


With the help of Mathias R. Jessen's answer, I ended up attaching an event to the application & system log with the following script:


$ComputerName = $env:COMPUTERNAME;

$To = ""
$From = $ComputerName + "";
$Subject = $ComputerName + " " + $LogName + " Error";
$SmtpServer = "";

$AppErrorEvent = Get-EventLog $LogName -Newest 1 | Where-Object { $_.EntryType -eq "Error" };

If ($AppErrorEvent.Length -eq 1) { 
    $AppErrorEventString = $AppErrorEvent | Format-List | Out-String;

    Send-MailMessage -To $To -From $From -Subject $Subject -Body $AppErrorEventString -SmtpServer $SmtpServer -Priority High;
share|improve this question
up vote 1 down vote accepted

No need to script your way out of that.

You can attach tasks to specific events in the Event Viewer, it works the same way in 2012 as in 2008: Right-click an instance of the specific event in the Viewer, and select "Attach a Task To This Event".

You can also attach a task to an entire event log.

The following article goes through setting up emailing task, specifically:

share|improve this answer
Thanks, I've already seen that article, that method forces me to define every error I want to be notified about, however I want any event where the EntryType is "Error" without having to know the EventID/Application/Specifics of the error. – Zeb Rawnsley Dec 16 '12 at 0:32
Attach a task to the entire Event Log, instead of a specific event, with the "Attach a Task to this Log" link in the Action pane in eventvwr. Have the task execute a powershell script that reads the latest eventlog entry and checks if it is an error – Mathias R. Jessen Dec 16 '12 at 0:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.