<> wrote in message
news:5ED75866-7568-4FA4-86C9-...
> 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.
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
|