Because there are many scheduled tasks on the R2 server, the mail notifies you if the task failed to run. Because the task fails to run, there will be a different event ID generated in the log, so if you have a different event ID, you should do another scheduled task.
Create a new scheduled task, type as follows, and set to do the following three configurations.
Select Run whether user is logged on or not.
Triggers configuration as.
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/6D/8E/wKioL1VmiWDSa0HBAAG-JPUukdo982.jpg "title=" 1.jpg " alt= "Wkiol1vmiwdsa0hbaag-jpuukdo982.jpg"/>
The Action is configured as follows.
Program Script C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
ADD arguments (optional) -command "C:\scripts\Task_Failed_Alert.ps1"650) this.width=650; "src=" http:// S3.51cto.com/wyfs02/m00/6d/92/wkiom1vmifsd6rzyaad9b83dcva499.jpg "title=" 2.jpg "alt=" Wkiom1vmifsd6rzyaad9b83dcva499.jpg "/>
The Task_failed_alert.ps1 script is as follows.
#This is script is for email alert when Event ID 101 Occur in task scheduler. $OutputFileLocation = "C:\scripts\Task_Failed_Alert.log" start-transcript -path $OutputFileLocation  -APPEND$ERRORMESSAGE = WEVTUTIL QE Microsoft-Windows-TaskScheduler/Operational "/q:*[system [(eventid=101)]" /f:text /rd:true /c:1 #Get eventid 101 lastest details in operational log$ComputerName = $ErrorMessage |select-string -pattern "Computer" #Display specific line $ComputerNames = $ComputerName. Line.split (".") | Select-Object -first 1 #Split specific phrase. $ErrorSubject = $ errormessage | select-string -pattern "Additional data" #Display specific line. $ErrorSubjects = $ErrorSubject.Line.split (".") | Select-Object -first 1 #Split specific phrase. $ErrorSub = "$ Computernames " + " " + " $ErrorSubjects "$ErrorMessage = $ErrorMessage | out-string #Formatting string for email Body.Send-MailMessage -From "[Email protected] " -To " [email protected] " -Subject " $ErrorSub " -Body " $ ErrorMessage " -SMTPServer SMTPSERVERWrite-Host " mail message sent on $ ( get-date -format ' s ') "write-host $ErrorMessage
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/6D/8F/wKioL1VmlIDAIWt4AAFzbu3Vz2U507.jpg "title=" 3.jpg " alt= "Wkiol1vmlidaiwt4aafzbu3vz2u507.jpg"/>
You can create an event ID 101 error by creating a new task to test the success of the above mail notification and running the task with a user with insufficient permissions.
Note that you do not set the default Notepad to open this script, or the task runs with Notepad to open the script instead of PowerShell.exe.
This article is from the "IT" blog, so be sure to keep this source http://simondu.blog.51cto.com/754321/1655904
Powershell Mail Notification scheduled task failed to run