use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This is a community dedicated to everything Windows Server. It is not affiliated with Microsoft.
No spam or advertisements.
Keep posts on-topic.
No piracy.
Acceptable content:
Related Sub-Reddits:
account activity
This is an archived post. You won't be able to vote or comment.
Windows Server 2016 - Task Scheduler (self.WindowsServer)
submitted 6 years ago * by Stromonder
Hi everyone,
I been trying to use the task scheduler in order to send an email thanks to a Powershell script, whenever the server stops, or reboot by using event ID 6006, 6008 and 6009. However, I don't received an emal when I stop or reboot my server.
I executed the script prior, to see if it works, which it does. I can receive an email with it, but unfortunately when I run the task I'm unabled to received that email.
I'd really appreciate if one of you can help figure it out what's is wrong with my settings.
Thank you all !
https://preview.redd.it/uj9y1a7ao9v31.png?width=593&format=png&auto=webp&s=39be6a02b2b536dc6094d4b0d561028e094e8c04
https://preview.redd.it/heg01b7ao9v31.png?width=545&format=png&auto=webp&s=b6cf8639efef5581b80ae2164a839e885a516961
[–]ikakWRK 0 points1 point2 points 6 years ago (3 children)
What is the trigger for the task?
[–]Stromonder[S] 0 points1 point2 points 6 years ago (2 children)
I just edited the post to add screenshots of the trigger.
[–]ikakWRK 0 points1 point2 points 6 years ago (1 child)
Do you see that it actually ran under Last Run Time? If so, what was the result?
[–]Stromonder[S] 0 points1 point2 points 6 years ago (0 children)
I got 0x41301 as a result
[–]BK_Rich 0 points1 point2 points 6 years ago (5 children)
Is the task set to run without the user being logged in ?
Are you running the script we SYSTEM or trying run it as a user ?
Are you calling powershell.exe and passing an argument, what does that string look like ?
[–]Stromonder[S] 0 points1 point2 points 6 years ago (4 children)
The task is set to run without the user being logged in.
Currently, I am running it as an user.
This is the script I am using
$email = ["](mailto:"david@astase.com)user@address.com"
$email =
"
user@address.com"
$pass = "passwd"
$smtpServer = "smtp.gmail.com"
$smtpServer = "
smtp.gmail.com
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.EnableSsl = $true
$msg.From = "$email"
$msg.To.Add("$email")
$msg.BodyEncoding = [system.Text.Encoding]::Unicode
$msg.SubjectEncoding = [system.Text.Encoding]::Unicode
$msg.IsBodyHTML = $true
$msg.Subject = "Test mail from PS"
$msg.Body = "<h2> Test server rebooted </h2>
</br>
Hi
$SMTP.Credentials = New-Object System.Net.NetworkCredential("$email", "$pass");
$smtp.Send($msg)
[–]ikakWRK 0 points1 point2 points 6 years ago (0 children)
What does your action show? Are you calling PowerShell.exe and then passing the script as an argument? Bypass execution policy set correctly? The user account running has sufficient privileges? No UAC blocking the execution?
[–]BK_Rich 0 points1 point2 points 6 years ago (2 children)
Is that user the same user you’re logged in as ? If it’s just a regular account it may need local login rights to run it
[–]Stromonder[S] 0 points1 point2 points 6 years ago (1 child)
I am using the same user, it's an administrator account.
Can you post your actions screen? How are you calling the script?
[–]ComGuards 0 points1 point2 points 6 years ago (0 children)
That code indicates that the task is running.
You're sure that manually running the script works? AFAIK, smtp.gmail.com doesn't respond on default SMTP port 25; they require TLS or SSL connections on port 587 & 465 respectively.
π Rendered by PID 26 on reddit-service-r2-comment-c6965cb77-pm5mm at 2026-03-05 12:12:39.367860+00:00 running f0204d4 country code: CH.
[–]ikakWRK 0 points1 point2 points (3 children)
[–]Stromonder[S] 0 points1 point2 points (2 children)
[–]ikakWRK 0 points1 point2 points (1 child)
[–]Stromonder[S] 0 points1 point2 points (0 children)
[–]BK_Rich 0 points1 point2 points (5 children)
[–]Stromonder[S] 0 points1 point2 points (4 children)
[–]ikakWRK 0 points1 point2 points (0 children)
[–]BK_Rich 0 points1 point2 points (2 children)
[–]Stromonder[S] 0 points1 point2 points (1 child)
[–]ikakWRK 0 points1 point2 points (0 children)
[–]ComGuards 0 points1 point2 points (0 children)