We’ve all run up against a scenario where a newly installed application will not work properly unless you reboot the server. The problem with that is you are probably working on the app during business hours and a reboot is out of the question right now. There are 2 easy ways to schedule a reboot of your Windows server to happen during off hours with no late night RDP sessions required.
*disclaimer*
Please test these procedures on a test box before using them on your production server. Also, there are several ways to do this, just Google them and you’ll see what I mean. This was performed on Windows 2008 R2 SP1.
Option #1 Using Task Scheduler and a batch file
To prepare your server for a late night/early morning reboot, do the following:
Open notepad and enter the following:
@echo off
echo rebooting the server
ping yahoo.com
shutdown /r /f /d p:4:1 /c "Planned restart by Techmom"
I inserted the ping to slow down the command just a bit so I can test it abort the shutdown with a shutdown /a at a command line.
/r = restart
/f= force running apps closed without warning users
/d = Provide reason for restart
p:4:1= Planned:Major:Minor = Application: Maintenance (Planned)
/c = Comment on the reason of the restart or shutdown
This is what you’ll see in the event log regarding the reboot. The comment is a good place to make a note of why the reboot must occur.
Once you know it works, time to create a task.
Open Task Scheduler. In the Actions Panel, click create task. Click each tab and choose the options that will allow you to perform your reboot. My settings are as follows:
General Tab
Trigger Tab, click New.
Action Tab, click new and browse to the batch script.
Conditions & Settings Tabs are with the default options selected.
Test the schedule to confirm the system will reboot.
If you are logged in during the test, you will see the warning popup informing you of the impending reboot.
Your server will reboot on the schedule you set. Review the event logs and the task scheduler library to confirm the reboot was successful.
Option #2 Use PSShutdown
PSShutdown is a Systernals utility that you can download from Microsoft to reboot local and remote machines. Follow the installation instructions before use.
This tool allows you to issue a psshutdown command from the command line, specify the reboot time as well as add parameters. To get a full list of the switches issue a PsShutdown /? at the prompt.
Open the command prompt and enter the command. In this example, I’ve chosen the following:
-r = reboot
-f = Force apps close
-t = Time to start shutdown
-m = Message
Upon reboot, review the event log for more information on your reboot.