The simplest way to schedule regular reboots or shutdowns of a Windows computer (or server) is to create a job in Task Scheduler.
Using a PowerShell script, you can create a delayed reboot task to schedule a computer reboot at a specific time.
[datetime]$RestartTime = '15:10'
[datetime]$CurrentTime = Get-Date
[int]$WaitSeconds = ( $RestartTime - $CurrentTime ).TotalSeconds
shutdown -r -t $WaitSeconds
Scheduled reboot tasks are used more often than one-time tasks. For example, you need to create a scheduled task that automatically reboots a Windows host every Monday at 3:00 A.M.
Creating an Automatic Reboot (Shutdown) Task in Windows Task Scheduler
Open the Task Scheduler console (taskschd.msc
) and run the task creation wizard: Action -> Create Basic Task.
Set the task name: RebootMonday
Configure a task schedule. In our example, this is a weekly task that runs every Monday.
Select Start a program. We will reboot the host using the built-in shutdown.exe command with the following parameters:
Program: %SYSTEMROOT%\System32\shutdown.exe
Add arguments (optional): /r /f /t 120 /d p:0:0 /c "Auto-reboot on Mondays. To cancel, run: shutdown.exe /a"
/r
— reboot/f
– force close all running apps/t 120
– a 120-second timeout before the system is rebooted/d p:0:0
— add the reboot reason to Event Viewer: Other (planned)/c
– display this informational message in active user sessions before rebooting the host.
In order to run a task automatically, regardless of whether there are active user sessions on the computer:
- Open the task properties in the Task Scheduler snap-in
- Select the option Run whether user is logged or not
- Click the Change User or Group button and type
SYSTEM
- Now the task will be run on behalf of NT AUTHORITY\SYSTEM.
- Make sure the task is enabled.
This host will now automatically reboot at the scheduled time and display a notification before the restart.
Wake-on-LAN can also be used to remotely wake up a Windows device.
This PowerShell script can be used to easily create a scheduled task with a reboot command:
$taskName = "WeeklyAutoReboot"
$taskDescription = "Automatically reboots the server every Monday at 04:00 AM"
$action = New-ScheduledTaskAction -Execute "shutdown.exe" -Argument "/r /f /t 120 /d p:0:0 /c `"Auto-reboot on Mondays. To cancel, run: shutdown.exe /a"
$trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Monday -At 4:00am
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest
Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal
Use Group Policy (GPO) to Schedule an Automatic Windows Shutdown or Reboot
If you want to schedule the auto shutdown or restart task on multiple computers in an Active Directory domain, you can create a scheduled task using Group Policy.
- Open the domain Group Policy Management console (
gpmc.msc
) and create a new Group Policy Object (GPO). Link the GPO to the organizational unit (OU) that contains the computers that need to be rebooted or shut down on a schedule. - Edit the new GPO and navigate to Computer Configuration -> Preferences -> Control Panel Settings -> Scheduled Tasks;
- Create a new task: New -> Scheduled task (At least Windows 7);
- Set the task name and configure it to run as the SYSTEM account.
- Configure a task schedule on the Triggers tab.
- On the Actions tab, add the shutdown.exe command with the described options.
- Save the changes.
- Update the GPO settings on the target client and verify that the scheduled Windows reboot task appears in Task Scheduler.
If you need to bind the automatic reboot/shutdown task to the completion of another task (for example, you want to restart the host after the backup task is successfully completed), see the example in the post “How to Run a Scheduled Task After Another Task Completes“.