SQL Agent Jovs : PowerShell step not sending notifications upon failure

  • Hello,

    I have setup a few jobs under SQL Server Agent and have configured them to send notifications via e-mail to me upon failure.

    The notifications appear to be working fine. However, there is one job that is setup in the same way using the same Operator for e-mail notification etc that doesn't send a notification e-mail upon job failure.

    The only difference with this job is that it has a PowerShell script in one step rather than a Transact SQL step. The job does indeed fail because I have deliberately altered a line of the PS script to a non-existent command and when I execute the job it does indeed report a failure.

    however, no e-mail is sent.

    If I change this job so that the notification is to be sent upon job completion as opposed to job failure, then I do receive an e-mail that tells me that Step 2 (the PowerShell part) of the job has failed, but there is no actual error message other than informing me that the job was started by me from step 1.

    Any ideas?

    Regards

    Steve

  • :hehe:

    ok check 2 links

    http://www.techrepublic.com/blog/10things/10-cool-things-you-can-do-with-windows-powershell/302

    http://www.databasejournal.com/features/mssql/article.php/3755411/Check-your-SQL-Server-using-Windows-PowerShell-150-Part-2.htm

  • Thanks for the links.

    However, after having a brief look at them, I wonder if you've (or perhaps me) have not quite grasped my issue.

    PowerShell works fine. I have been able to execute PowerShell scripts via SQL Agent jobs without a problem. The only oddity is that when trying to run a script with a deliberate error in the code (thus inducing a failure) the associated job notification that I've set up doesn't send me an e-mail informing me of the job failure.

    I wondered why this should not work when a powerShell script fails, but does work and send appropriate notifications when a T-SQL script fails.

    However, if I've misunderstood your help, then please accept my apologies.

  • Check your -erroraction in the event of a problem. I would normally set the script -ErrorAction "stop"



    Shamless self promotion - read my blog http://sirsql.net

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

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