The best way to do this is to create a suitable event-triggered task. (This runs a script upon shutdown, rather than replacing it, which would be a bad idea.)
Open Event Viewer, and find the shutdown event that you want to trigger the task on (e.g. in the "Windows Logs"->"System" log, filter for Source "User32" and Event 1074). Now on the right-hand panel, you'll find an "Attach Task To This Event..." option; select this to bring up a "Create Basic Task Wizard" dialog.
This is the normal Task Scheduler dialog for creating basic tasks; fill it in as normal (you'll notice that you can't change the event details), selecting "Start a program" as the task to perform, and setting the script you wish to run. Finish the task, and edit it if you want to set more advanced properties.
Note that the example above will only work for user-triggered shutdowns (including those from scheduled tasks); if you have other forms of shutdown, you'll need to find an example of the corresponding events to create the task from. If you only have the log, source and event ID, you can export an existing event-triggered task to file, edit the (XML) file appropriately with the log, source and event ID, and import it back into Task Scheduler.