If you need to get notified when something happen in the event log
How it works:
1) In Event viewer, select the event you want to get notified. Right click it and select “Attach a Task To this Event…”

2) Follow the wizard. Give a Name

3 ) Click on next

4 ) Step 4 :
- Program/script = c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe
- Add Argument .\senderror.ps1 “Application” (The Windows Logs name, I setup the “Application” log)
- Start in = c:\temp
- Next
5 ) Step 5 :

Click on next

5) Save the script file in c:\temp with the name senderror.ps1 .
—————————————————————————————
# Pass The event Name value to $NAmeEV
$NameEV = $args[0]
# Delect the newest log
$event = Get-EventLog $NameEV -newest 1
# “Error” – send only error
if ($event.EntryType -eq “Error”)
{
$PCName = $env:COMPUTERNAME
$EmailBody = $event | Sort-Object EntryType,Message,TimeGenerated | Out-String -width 4096
$EmailFrom = “$PCName <[email protected]$PCName>”
$EmailTo = “Youremailaddress”
$EmailSubject = “New Event Log ($NameEV) [$PCName]”
$SMTPServer = “smtp.sendgrid.net”
$secpasswd = ConvertTo-SecureString “yourpassword” -AsPlainText -Force
$credentials=New-Object System.Management.Automation.PSCredential(”yourusername”,$secpasswd)
Write-host “Sending Email”
Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -body $EmailBody -SmtpServer smtp.sendgrid.net -Credential $credentials
}
About Sendgrid