2

How can I configure Windows 11 pro to send an email immediately prior to shutdown?

I've written a simple powershell script to send an email (this works fine) but I'm having trouble persuading the task scheduler to run it successfully.

Task details.....

  • Basic Task, 'on an event'
  • log is set to 'system'
  • Source is 'user32'
  • Event Id 1074
  • Run with highest privileges

Running the schedule manually seems to work fine, the script runs and the email is sent.

If I select 'shutdown and reboot' the system shuts down and reboots as expected. After the reboot the event viewer indicates an event of ID 1074 has occurred.

The history for the task also indicates that the task has run successfully, it's triggered, created, started and completed without problem (according to the task schedule history). However, the email never get's sent, and the log file (for the powershell script) doesn't exist which suggests it was never actually runs, despite what the task history may claim.

Why isn't the script actually being called, and how can I fix it?

3
  • social.msdn.microsoft.com/Forums/Lync/en-US/…
    – Gantendo
    Commented Jun 27, 2022 at 16:14
  • @Gantendo - add that into an answer and I'll accept it. Thank you. I spent hours googling this problem and never found this solution, but it only took 10 seconds to implement. Well done. Commented Jun 27, 2022 at 17:46
  • Feel free to answer your own question and accept it so you'll get some karma.
    – Gantendo
    Commented Jun 28, 2022 at 4:13

1 Answer 1

2

Instead of using Task Scheduler, use the group policy editor to add a shutdown script.

Press Win + R and type gpedit.msc, then follow the path in the image below to add your shutdown script.

enter image description here


Answer, following the link suggested by @Gantendo in comments.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .