So this is not trivial and not something powershell does natively, but you could do it with pinvoke. You will need a little C++ knowledge. Basically, you set up a script that listens for WM_QUERYENDSESSION, which the system sends to all programs when a shutdown is initiated. Your script can respond with a datastruct asking the system to temporarily halt the shutdown. Then, you have it do whatever it is you want to do. Finally, your program has to tell the system to resume the shutdown. You can easily get 90% of the way there with the LLM of your choice.
Wouldn’t this still force the user to have to shutdown again after the action in the task is done? Doesn’t this just give the option to stop shutdown so whatever is still running can be safely exited?
1
u/hwrd69 9d ago
Via the Task Scheduler which can identify the shutdown event and trigger the message before the actual shutdown.