trying to send alert in application log

  • looking to catch the dreaded 14151 errors on replication and below code is not sending an alert.

    in production i'm obviously going to change the -eq to -gt 1. and increase the timeout a bit

    $date = get-date

    wait-event -timeout 30

    $result = (get-eventlog -logname application -after $date -source mssqlserver | where-object { $_.eventid -eq 14151 }).count

    if ($result -eq 0)

    {send-mailmessage -to "","","","" -from "" -subject "Check SQLREPL" -body "Errors on SQLREPL" -smtpserver}

  • Well to me at least the send-mailmessage statement looks fine. Have you checked that from that server you are able to send e-mail via that smtp server without logging in or anything?

    Easiest way to check is to send a mail via a telnet connection, which should then give you a like for like setup. If you don't know how to do it there's a good guide here

  • got it figured out with help from the MSDN forums

    if there are no events it's not a 0, but a null or some other kind of value. i've had this running where the conditions are gt 0 and it works pretty good

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply