April 28, 2017

“Send an e-mail”-Windows Server 2012 Task Scheduler deprecated feature [SOLVED!]

One of most common and lethal tool windows administrator is aware of when you want to send an automated email from task scheduler. However if you ever tried to set a windows task which will required to send an email in Windows server 2012, you will soon realize that it has been deprecated.

When you try to create a task through the task scheduler wizard, it does shows you option “Send an e-mail” but note what’s there is the bracket!

image1

If you try to even go further in the wizard, it refuses to accept and dialogues out as ‘deprecated feature’.

image2

Well you certainly have the most trusted PowerShell to salvage.

Resolution:

We will work here with both the windows task manager feature and PowerShell script, where task will be created in Task manager and email will be sent using  “ Run a Program/Script “  option in Action stage of setup.

Here we will see how to send email using Windows PowerShell and configure a Task in Windows Task Manager and setup email notification.

  1. Open notepad > Copy below Script > Change the highlighted with your details > save the file as PS1. e.g.  “EmailScript.PS1”
    $SmtpClient = new-object system.net.mail.smtpClient
    $MailMessage = New-Object system.net.mail.mailmessage
    $SmtpClient.Host = "SMTP.YOURcompany.com"
    $mailmessage.from = ("DoNotReply_ToThisEmail@ YOURcompany.com ")
    $mailmessage.To.add(" Person@ YOURcompany.com , Person2@ YOURcompany.com, …… ")
    $mailmessage.Subject = “Alert Subject
    $mailmessage.Body = “Alert Body with Instruction to recipients
    $smtpclient.Send($mailmessage)
  2. Create a basic task image3
  3. Select When A specific event Logged image4
  4. Select and furnish any trigger for which you want e-mail alert image5
  5. On next screen select “Start a program” image6
  6. In program/script à type powershell.exe à In argument give the path of EmailScript.PS1 with file name image7
  7. Check Open Property Dialog à Now Click Finish image8
  8. Check over the below options matches image9 image10 image11
  9. Similarly you can put multiple triggers of Event IDs image12

Leave a Reply

Your email address will not be published. Required fields are marked *