Restarting a server at a certain time from accross the LAN.

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

Related Posts

ThinIO facts and figures, Part 3: RDS and Ram cach... Welcome back to the third instalment of this blog series focusing on our new technology ThinIO! To recap, below you will find the previous articles...
The curious case of the major XenApp outage. Here's a really strange and interesting issue I faced late last week that resulted in a few head scratching moments and late nights. An Issue began...
Viewing open files on a file server from powershel... So this is a situation you should all be aware of in an SBC / VDI environment, despite all warnings, you've redirected folders to your network drive a...

2 Comments About “Restarting a server at a certain time from accross the LAN.

  1. Mike

    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.

    Reply

Leave a Reply