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!
If you try to even go further in the wizard, it refuses to accept and dialogues out as ‘deprecated feature’.
Well you certainly have the most trusted PowerShell to salvage.
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.
- 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”
- Create a basic task
- Select When A specific event Logged
- Select and furnish any trigger for which you want e-mail alert
- On next screen select “Start a program”
- In program/script à type powershell.exe à In argument give the path of EmailScript.PS1 with file name
- Check Open Property Dialog à Now Click Finish
- Check over the below options matches
- Similarly you can put multiple triggers of Event IDs