How to schedule a task to run when the windows server is reboot or shutdown

schtaskswindows-server-2012

I would like to be able to fire a task before a windows server 2012 is reboot or shutdown.

I can see task scheduler supports an 'on startup' trigger. Unfortunately there is similar event for reboot or restart. Is there anyway I can achieve the my goal?

Best Answer

You cannot use the task scheduler for running scripts on shutdown, but you could instead use shutdown scripts supported by Group Policy. Shutdown scripts are run as Local System.

You can find them under Computer Configuration\Windows Settings\Scripts (Startup/Shutdown)