Just a quick entry as i got an email requesting this today, “How can i schedule a restart on a remote server to run out of hours?”
This script uses at.exe which is soon replaced by schtasks.exe. This can only be run by an administrator of the server you wish to restart, obviously.
Rem setting vars:
set server=servertorestart
set time=05:00
REM performing check for previous file and deleting it:
if exist %server%c$rebootme.bat del %server%c$rebootme.bat
Rem Creating reboot batch file:
echo shutdown -r -t 03 >> %server%c$rebootme.bat
Rem Scheduling the job:
at %server% %time% c:rebootme.bat
To Create a reusable, error checking script with idiot proof options! save the following as a .bat file:
@echo off
cls
Rem setting vars:
set /p server=[Please enter the name of the server you wish to restart:]
cls
echo Selected server = %server%
set /p time=[Please enter the time in HH:MM format at which you wish to restart the server: e.g. 05:00]
cls
REM performing final idiot check
echo Are you absolutely sure you wish to restart %server% at %time%?
Pause
REM performing check for previous file and deleting it:
if exist %server%c$rebootme.bat del %server%c$rebootme.bat & echo deleted previous file
Rem Creating reboot batch file:
echo shutdown -r -t 03 >> %server%c$rebootme.bat
Rem Ensuring reboot file exists:
if exist %server%c$rebootme.bat echo reboot script created successfully.
if not exist %server%c$rebootme.bat goto Failed
Rem Scheduling the job:
at %server% %time% c:rebootme.bat
Echo Job scheduled, Script complete.
pause
:failed
echo something failed, I’d look into that if i were you.
pause
exit


I usually use psshutdown from the wonderful pstools for this.
psshutdown servername -u domainusername -r -f -t 01:15 -e p:02:17
This will restart the server at 01:15am, force any apps to close and enter a shutdown code 02:17 (planned patch reboot). It will prompt for password or you can add a -p in there too.
Nice touch! I wasnt aware of the time option for psshutdown, learn something new every day