Monitor Scheduled Job Status

Discussion in 'Scripting' started by Guest, Jul 27, 2008.

  1. Guest

    Guest Guest

    I'd like to create a script that sends email if Scheduled Job task has
    failed. Can somebody post an example?

    PowerShell script is preferred, but VBScript is fine as well.
     
    Guest, Jul 27, 2008
    #1
    1. Advertisements

  2. The easiest way is probably to monitor the commands that
    get executed by the scheduled job and invoke the VB Script
    file below when something goes wrong:

    schema = "http://schemas.microsoft.com/cdo/configuration/"
    Set objEmail = CreateObject("CDO.Message")
    With objEmail
    .From = ""
    .To = ""
    .Subject = "Task Scheduler Error Report"
    .Textbody = "The quick brown fox " & Chr(10) & "jumps over the lazy dog"
    .AddAttachment "d:\Testfile.txt"
    With .Configuration.Fields
    .Item (schema & "sendusing") = 2
    .Item (schema & "smtpserver") = "mail.Izorich.com"
    .Item (schema & "smtpserverport") = 25
    .Item (schema & "smtpauthenticate") = cdoBasic
    .Item (schema & "sendusername") = ""
    .Item (schema & "sendpassword") = "somepassword"
    End With
    .Configuration.Fields.Update
    .Send
    End With
     
    Pegasus \(MVP\), Jul 28, 2008
    #2
    1. Advertisements

  3. Guest

    Guest Guest

    I know how to send email from scripts. The question is how do I get WMI
    event that scheduled job has failed? Or how do I monitor status of scheduled
    jobs in general.
     
    Guest, Jul 28, 2008
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.