I would like to schedule a one-time server restart, e.g. to finish installing updates early in the morning. How can I do this from the command line on Windows 2012?

On Windows 2008, I would have used the at command,

at 2am shutdown -r -f -c "restart"

and taken the rest of the afternoon off.

But on Windows 2012, running this command tells me that

The AT command has been deprecated. Please use schtasks.exe instead.

So the equivalent command with schtasks.exe might be

schtasks /create /sc once /tn restart /tr "shutdown - r -f ""restart""" /st 02:00

Apart from being very forgettable, this command has another important downside: it schedules the task for 2am today—not much use unless I'm awake at 1am to run it.

According to the help for schtasks.exe, the /sd switch for setting the start date is not applicable with /sc once. So even if I wanted to type out tomorrow's date in mm/dd/yyyy format—and I don't—I can't do this.

The only possible solution I've found is here, where Kevin Traas suggests creating batch file to create a scheduled task just before midnight that waits for a couple of minutes and then creates another scheduled task to run the command that you actually want to run. Clever, but nowhere near as convenient as at.

  • @Lijo that link doesn't contain any information about how to schedule a restart.
    – user37944
    Jul 1 '17 at 23:37
  • This is just total stupidity to replace AT with unusable schtasks. Why they couldn't make both? Jerks!
    – midenok
    Dec 6 '18 at 0:11

The shutdown command itself has a delay parameter /t that delays a shutdown for a number of seconds up to 10 years. If you want to schedule a shutdown in 14 hours, say, you might run

shutdown /r /t 50400

You might also add a reason with the /d parameter or a comment with /c; run shutdown /? for details.


Despite the documentation, the /SD parameter seems to be compatible with the /SC ONCE. The task is successfully created to run on the date provided, at the time provided. (Tested on W8 and W7)

Additionally, the XP documentation for schtasks.exe goes so far as to say the /SD parameter is required when using /SC ONCE, so I imagine there are a fair number of scripts using the combination.


C:\Users\Mitch>schtasks /create /sc once /tn restart /tr "shutdown -r -f ""restart""" /st 23:00 /sd 2013-06-13
SUCCESS: The scheduled task "restart" has successfully been created.


If going against the documentation does not sit well with you, consider generating the XML file directly (schema is here), which is definitely supported and definitely supports a task scheduled to run once on a future date. An easy way to get the proper file is to create it in the Task Scheduler mmc snap in and use the export command.


<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
    <Principal id="Author">
  <Actions Context="Author">
      <Command>Your command here</Command>

Command to import:

schtasks /CREATE /TN "Task Name" /XML filename.xml
  • Thanks for the tip about /sd being supported. That's interesting about the XML import too—although personally I don't care about going against the documentation. So at least this is possible—just much, much more difficult than it used to be with at.
    – user37944
    Jun 13 '13 at 3:25
  • Mildy interesting: /sd doesn't work with /sc once on Windows Server 2008. It results in ERROR: Incorrect Start Date.
    – user37944
    Jun 13 '13 at 7:06
  • 4
    Hmm... I additionally tested Server 2008 SP2 and Server 2008 R2 without issue. I will note that the date format is based off of your local date/time format, and leading zeroes are required. In the default EN-us install, this would lead to formatting like /SD 06/14/2013.
    – Mitch
    Jun 13 '13 at 20:59

I ended up creating runat.ps1 to replicate some of the simple features of at, incorporating the wisdom from Mitch's answer.

The syntax is runat (time) (command), e.g.

runat 2am shutdown -r -f -c "restarting the server"
runat 10:15 msg * it`'s 10:15 everyone!

If you, too, are nostalgic for the good old days when you didn't have to type...

schtasks /create /ru system /rl highest /sc once /tn restart /tr shutdown -r -f -c \"restarting the server\" /st 02:00 /sd 06/15/2013

... then you can install it by running this powershell command:

iex (new-object net.webclient).downloadstring('https://gist.github.com/lukesampson/5779205/raw/install.ps1');install runat https://gist.github.com/lukesampson/5778559/raw

Or you can manually download runat.ps1 script here.

  • 1
    +1 That is a very helpful script... this is definitely going in my favorites.
    – Mitch
    Jun 14 '13 at 17:47

I used this in a script for 2012 R2 and works nicely; It will create a daily task that restarts the server @ 4:30am

schtasks /create /ru system /rl highest /sc DAILY /tn restart /tr "shutdown /r /f /c "Restarting" /st 04:30

Please make sure that you run this from a CMD prompt with Administrative privileges.



Just another powershell script to programatically reboot the computer the next day at specified time

$tomorrowDate = (get-date).AddDays(1).ToString("dd/mm/yyyy")

schtasks /delete /tn restart /f
schtasks /create /sc once /ru MyDomain\administrator /rp /tn restart /tr "shutdown -r -f" /st 07:13 /sd $tomorrowDate

I suggest using the schtasks command with the /f parameter.

Using /f, if there is a task with the same name, it's modified.

It's very useful for deploy tasks via scripting.

A full example of a schedule server restart:

schtasks /create /ru system /rl highest /sc DAILY /tn Reinicio /tr "shutdown /r /f /t 0 /c "Reinicio"" /st 22:30 /F

Extracted from: http://www.sysadmit.com/2016/09/windows-programar-apagado-o-reinicio-automatico.html


If the goal is simply to reboot after installing updates, then you can use the PSWindowsUpdate module to install the updates. You can download it from here. Once installed, just open Powershell and type

Get-WuInstall -AcceptAll -AutoReboot

This script lets you schedule the Restart of multiple servers at a specific date / time.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy