0

I wrote a powershell script to make a database dump that I plan on having run nightly with Windows Task Scheduler. It outputs to a log file so I can make sure everything is working, but I want to be informed when something goes wrong without having to check the log manually. My idea was to create a Windows event log for this and other custom scripts and have them all record errors in it. I would like to be notified somehow when an error occurs in this log, such as by sending me an email. Is there a way to do this? I am running Windows 7.

0

Give this a shot. You can define where the logs go, what the error code is, etc. Make it your own. If you want to use gmail to send the message, there's a tutorial I saw a while back. I'm sure you can find it.

Try
{
Database dump commands
}
Catch
{
    Write-EVentLog -LogName Application -Source "Baller Script" -EntryType Error -EventID 42 -Message "There has been a failure..."
    Send-MailMessage -From ExpensesBot@MyCompany.Com -To bro@baller.com -Subject "DBDump is broke as hell! (Event ID: 42)" -SmtpServer exch@baller.com
    Break
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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