Windows server task scheduler перезагрузка сервера

Имеем Windows Server 2012 R2. Задача - автоматически перезагружать сервер каждый понедельник в 5 утра. Приступаем.

Profile picture for user Олег

Windows Server

Имеем Windows Server 2012 R2. Задача — автоматически перезагружать сервер каждый понедельник в 5 утра. Приступаем.

Запускаем Планировщик заданий, создаём в нём папку «reboot»:

reboot

Делаем Create Basic Task… Запускается мастер:

reboot

Указываем Name, Description:

reboot

Кликаем Next:

reboot

Выбираем период Weekly. Next:

reboot

Указываем начало — ближайший понедельник 5 утра. Ставим галку Monday. Next:

reboot

Выбираем Start a program. Next:

reboot

В Program/script: пишем:

%SYSTEMROOT%System32shutdown.exe

В Add arguments (optional):

/r /f /t 90 /d p:0:0 /c "Перезапуск по понедельникам. Отмена: shutdown.exe /a"

Где:

  • /r — перезагрузка,
  • /f — принудительное закрытие всех приложений,
  • /t 90 — время ожидания до начала перезагрузки 90 сек,
  • /d p:0:0 — причины перезагрузки для журнала. В данном случае, мы указали: p — запланированная перезагрузка, 0:0 — «Other (planned)»,
  • /c  комментарий в свободной форме длинной не более 512 символов. Комментарий будет показываться юзерам 90 секунд. За это время можно отменить перезагрузку командой shutdown.exe /a.

Список параметров и причин перезагрузки можно посмотреть shutdown.exe /?

reboot

Мастер не доделали, кликаем Finish. Создаётся задача  — редактируем её.

win

Ставим Run whether user is logged on or not. Добавим галку Run with highest privileges. Ok:

reboot

Нас попросят ввести имя пользователя, от имени которого будет выполняться задание. И пароль. Готово:

win

Сам пока не проверял результатов. В ближайший понедельник посмотрим…

P.S.

Две недели прошло — шедулер нормально перезагружает сервер по понедельникам.

This blog has detailed how to schedule Windows Server Reboot Automatically (Windows or Server 2008/2019). You may want to reboot a Windows Server once a week or month as a matter of routine maintenance. It’s particularly useful too. Say if you want to reboot a server because you installed particular software that you didn’t expect needed a restart, or there are some updates. You cannot really do it unless after hours and you don’t need to hang around and then you would just like it to reboot itself a couple of hours after working hours when everyone left.

Note: I’m using Windows Server 2019. This is almost the same as in 2008/2012/0216.

Schedule Windows Server Reboot Automatically

1- Select search bar and type Task Scheduler, click on it to open. You can find it by clicking on the Windows start button, expand Windows Administrator Tools, open Control Panel to select Administrative Tools.

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

2- Create a new basic task using the Create Task action.

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

3- Type a name to the task. I renamed it Restart Server or (Restart This Server). Type a description Schedule Windows Server for Automatically restart. Click next

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

4- Since this task is to just restart the server one time (select one time) and then click next.

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

5- Provide it a date and time to restart. Click next.

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

6- Select Start A Program action and then click Next.

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

7- Type shutdown into the Program/Script box and then /r into the Add arguments box. Click Next.

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

8- Click Finish.

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

9- We are almost done if you want this to run if you get logged off and you want to set this up so you can use it again later. In the Task Scheduler right-click on your new task and then select Properties.

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

10- This will show up on the general settings page. The default settings are “Run only when the user is logged on” switch it to “Run whether the user is logged on or not”. Choose configure to select the Server you want to reboot.

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

11- Select ok, after typing your administrator password.

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

Changing the Schedule for The Automatic Reboot

So now we have a task that will automatically reboot our Windows server (Computer, PC) one time.

12- Go back to the Task Scheduler Window, right-click on the task and then click Properties. Select the Triggers tab.

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

13- Select the One Time trigger and then click the Edit button. Change the time and date, click ok and your server/PC/computer will now restart at the new time.

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

14- When you click ok it will ask you to re-enter the administrator password.

Schedule Windows Server Reboot Automatically, How to Schedule Windows Server Reboot Automatically

Watch Video: How to schedule Windows Server reboot automatically.

How to schedule Windows Server reboot automatically

 
This is one of those really basic tasks you can easily set up with no added software or even Powershell scripts. It’s extremely useful too. Say you need to reboot a server because you installed some software that you didn’t expect needed a reboot, or there’s some updates, or some other reason. You can’t really do it until after hours and you don’t want to hang around and would just like it to reboot itself a couple of hours after closing time when everyone is home.
You might also want to reboot a Windows Server a month or once a week as a matter of routine maintenance.
This is fairly trivial to set up in Task Scheduler.

Note: I’m using Server 2016. This is almost exactly the same in 2008 and 2012.

Step 1 – Open Task Scheduler. In the newer versions of Windows Server you can just click on the start button and type “Task Scheduler”. You can find it manually under Control Panel under Administrative Tools. You can find it in the Start Menu in Server 2003 but the Task Scheduler is a bit different.

Step 2 – Right Click on the Task Scheduler Library (Highlighted in the picture in Step 1) and click “Create Basic Task”. This will open the Wizard. You don’t have to use the Wizard, but since this is a very simple task it’s easier.

Step 3 – Give a name to the task. I called this “Restart Server Once”. In a multi-server environment, my personal preference is to call it “Restart This Server Once” or “Restart Local Server Once” to show that the task restarts that specific machine. As I usually also have tasks to restart remote servers and workstations on at least one of them as well. If I were also making one to restart the box on a schedule I’d name it something like, “Restart Local Server On First Of Month”.

Click Next.

Step 4 – Since this task is to just restart the server one time click the “One Time” option and then click next.

You’ll note the sub-task called “One Time” under triggers.

Step 5 – Give it a date and time to restart. Click next.

I chose 8pm the next day.

Step 6 – Select “Start A Program”. Click Next.

Step 7 – Type “shutdown” without the quotes into the “Program/Script” box and “/r” into the “Add arguments” box. Click Next.

Step 8 – Click Finish

Step 9 – You aren’t done yet because you want this to run if you get logged off and you want to set this up so you can use it again later.  In the Task Scheduler right-click on your new task and click Properties. This will bring up the general settings page. The radio buttons on the bottom will default to “Run only when user is logged on” change it to “Run whether user is logged on or not”.

Step 10 – Click OK. It will make you enter your administrator password.

You’re finished!

Changing the Schedule for The Automatic Reboot

So now you have a task that will automatically reboot your server (Or PC) one time. Now  you need it to do it again. There’s no need to make another task, you just need to update the trigger.

Step 1 – Go back into Task Scheduler, right-click on your task and click Properties. Click on the Triggers tab.

Step 2 – Click on the “One Time” trigger and click the Edit button. Change the time and date, click OK on all the dialog boxes and your server/PC will now restart at the new time.

It will ask  you to re-enter the administrator password.

Despite the common belief, the practice of programming a system reboot or shutdown of a client or server machine isn’t necessarily a bad thing: in some limited scenario planning a regular shutdown or reboot of the operating system could be a decent workaround to securely put the machine in a desired state — for example, to make it ready for a VM-based backup or for installing a planned update. Depending on the situation, it could even be acceptable to setup a recurrent period — once a week, for example — to issue a system reboot. 

The ideal interval, needless to say, might vary a lot depending on the features performed by our server, its service availability expectactions and other variables in play: if the server performs its activities only during daytime can probably be restarted every night without major issue, while a web server that serves sites or services troughout the world should be restarted only in exceptional circumstances. It’s also worth noting that you can often get the same benefits by recycling the Application Pools or other resource-heavy processes, as we’ll see in a short while.

Setting up our machines to reboot at regular intervals could also be useful to ensure that the system will be able to get back on track in case of a planned reboot — such as those issued by system updates or due to unforeseen situations — service interruption, power failure, hardware failure and other more or less serious events that could always happen. Since the ability to recover after those unexpected events is the fundamental premise of any Disaster Recovery procedure, setting a reboot at regular intervals might also be a not-so-terrible way to periodically test our system against these kind of threats.

To set up an automatic system restart, open the Control Panel (if you do not know how to do on Windows 10, read here) and open the Task Scheduler in the following way, depending on your version of Windows:

  • Windows 2000/XP, Windows Server 2003 and previous versions/builds: select the Task Scheduler (or Scheduled Tasks) icon.
  • Windows Vista, Windows 7/8/8.1/10, Windows Server 2008 and newer versions: open the Administrative Tools folder, then select the Task Scheduler icon.

windows-8-task-scheduler-icon

Once the Task Scheduler window is open, create a new task using the  Create Task action in the following way:

task-scheduler-create-taskA modal window will be opened: use the General tab to setup a name and a description to the new task. Other than that, it can be useful to properly setup the following options:

  • Run whether user is logged on or not, to ensure that the task will be executed even if there are no logged-in users.
  • Run with highest privileges, to make sure that the task will be executed with administrator rights — this is required for issuing a system hutdown or a reboot.

task-scheduler-general

For further info regarding the other options, check out this MS TechNet article.

Once done, move to the Trigger tab and click on the New button to create an execution trigger — which is, the event that will make the system run the task itself. A New Trigger modal window will then be opened, which you can use to setup such event. The most common trigger to setup here is a time-based trigger, which can be set by selecting the On a schedule option on the Begin the task dropdown list:

task-scheduler-create-trigger

Il trigger che abbiamo creato eseguirà l’attività ogni notte alle ore 04:00.

For further info regarding triggers, take a look at this MS TechNet page.

Once done, move to the Actions tab and click to the New button to setup the command to execute whenever the trigger fires.

Setup an automatic Shutdown (without reboot)

%SystemRoot%system32shutdown.exe s f t 10

Setup an automatic Reboot

%SystemRoot%system32shutdown.exe r f t 10

Here’s a brief explanation of the parameters used above:

-s : setup the automatic shutdown of the system without a reboot. Alternative to the -r option (see below).

-r : setup the automatic reboot of the system: this option is required to ensure that your system will actually restart. Alternative to the -s option (see above).

-f : ensure that all the processes, services and user sessions will be forcefully closed before performing the shutdown or reboot: this is a required option to ensure the shutdown even there are active processes that cannot be terminated in a graceful way; be sure to only use it if you don’t have active user sessions and/or running processes that performs critical tasks (such as backup jobs, anti-malware scans and the likes), as they will most likely be killed before completion.

-t : setup a timeout before executing the shutdown or reboot (in seconds): the default is 20 (20 seconds), but can be changed by adding a number right after it, separated by a space: for example, -t 50 for 50 seconds. This option is great to use because it will also show a warning popup to logged-in users (if there are any) when the shutdown/reboot time occurs, allowing them to close their tasks and log out.

For a detailed explanation of all the shutdown.exe options and parameters, you can take a look at this official MS TechNet doc.

As soon as you define the Action, your planned activity should be ready: take a few seconds to check all the settings once again, then click OK to create the task. If you asked to run the task with elevated privileges the system will ask you to enter the credentials of the Administrator account (or the account with administrative privileges you have chosen in the General tab): once done, the result of your work will appear, summarized in a single line, within the Task Scheduler main panel:

windows-8-task-scheduler-actions

Un esempio del pannello «Actions» del Task Scheduler di Windows 8.

A good thing to do before closing everything is to run the task immediately to prove it works (right mouse button -> Run): alternatively, you can just wait for it to occur automatically at the time you have set and then check the Last Run Time / Last Run Result parameters to determine the outcome.

Conclusion

That’s it for now: I hope that this small tutorial will help other System Administrator looking for a way to setup an automatic shutdown and/or reboot on Windows. In case you need to do the same on Linux machines, check up this post!

This article has detailed steps to schedule a restart of your Windows VPS Machine 2008/2012/2016. This can be achieved by just adding a task at task scheduler of your Windows Server Machine.

  1. Login into your Window server remote desktop.
  2. Open Run prompt, type taskschd.msc, and click ok.

taskschdmsc 1 - How to schedule reboot of windows server 2012 , 2016?

Open Run prompt

3. Now Go to Action >> Create task.

create task 640x364 - How to schedule reboot of windows server 2012 , 2016?

4. set the name of your task and select the operating system of your windows vps from drop-down.

Please remember to check the following option :
a. Run whether user is logged on or not
b. Run with highest privileges

create task2 1 640x444 - How to schedule reboot of windows server 2012 , 2016?

5. Now Go to Trigger tab and schedule the time of reboot. (by clicking on New…) in this stage, you can define the time you want to schedule a reboot. (weekly, daily, or monthly)

trigger1 640x486 - How to schedule reboot of windows server 2012 , 2016?

trigger2 640x510 - How to schedule reboot of windows server 2012 , 2016?

How to schedule reboot of windows server 2012 , 2016?

6. Now set the reboot action with adding command C:WindowsSystem32shutdown.exe with add argument /r and click ok. (by clicking on Action Tab)

action 640x484 - How to schedule reboot of windows server 2012 , 2016?

That’s all. This machine (VPS , VM and other ..) is now set to reboot every weekend.








Home
Login
Join



  1. Learn
  2. Windows
  3. Windows Server
Author Scott D.
Scott D.


Last Updated:

Jan 17, 2018
1 Minute Read

  • Spice
  • Reply (18)
  • Subscribe

  • Share
    Opens a new window

    • Facebook
      Opens a new window

    • Twitter
      Opens a new window

    • Reddit
      Opens a new window

    • LinkedIn
      Opens a new window

Author Scott D.

Scott Danton

Scott D.26 years in ITMCSA, MCSE
Badge Voice of IT
Badge Spiceworks Survey
Badge Review Champ Level 1
Badge Review Champ Level 2
Badge Review Champ Level 3


85
Contributions
3
Best Answers
3
Helpful Posts

Main Areas of Contribution:
  • Spiceworks General Support |
  • General Linux |
  • Nagios |
  • Cisco |
  • Microsoft Exchange
Register. Track Progress. Earn Credits.
Learning has never been so easy!

Sign Up

Task Scheduler

The Task Scheduler is a Windows component that can automatically run tasks at a specific time or in response to a specific event. For example, tasks can be run when the computer starts or when a user logs in. You can start tasks when a specific event occurs and using task scheduler you can run commands and execute scripts on a specific day and time.

Getting Started

Search task scheduler in Windows search.

Right-click on Task Scheduler and click New Folder and give a name to the folder like Server Reboot and click OK.

Automate Server Restart Using Task Scheduler

Making a folder makes your tasks separate, so you can manage easily.

Automate Server Restart Using Task Scheduler

Now right-click on new created folder and select Create Task.

Automate Server Restart Using Task Scheduler

Give a task name and description and select Run whether user is logged on or not and select Run with highest privileges in General tab.

Automate Server Restart Using Task Scheduler

Now click on Triggers tab, which is for restart scheduling date and time. In my trigger I am choosing to run this task every week on Sunday only, you can choose based on your requirement.

Click New.. button to create a new trigger and select required details and click OK.

Automate Server Restart Using Task Scheduler

Now let’s go to Actions tab, click new button to create an action. Enter Program/script path and arguments and start in values and click OK.

Automate Server Restart Using Task Scheduler

Now select Conditions tab and keep power settings as it if nothing needed.

Automate Server Restart Using Task Scheduler

Now click on Settings tab. I am stopping my task if runs longer than 2 hours and click OK.

Automate Server Restart Using Task Scheduler

Now you can see your task is ready to run on given schedule if you want to run anytime just hit the Run button.

Automate Server Restart Using Task Scheduler

Conclusion

In this article, we have learned how to create a new task and set up a server restart using Windows 10 Task Scheduler.

There are many reasons you may need to restart a server via task scheduler.  My favorite reason is so I can reboot the server after patching without having to work late.  🙂

This example will restart a server every morning at 6:00 AM Monday through Friday, but will not restart it on the weekends.

Start / Administrative Tools / Task Scheduler

Right-click Task Scheduler Library (or optional sub folder) and create task.

General Tab
Name: Descriptive name such as: RestartOneTimeMorning0600am or: RestartWeeklySundayMorning0130am
Description: Put in your own description, such as: Scheduled after-hours server restart
When running the task, use the following user account: NT AUTHORITYSYSTEM
* (Note: Select “SYSTEM” when browsing using “Change User or Group…”)
Check “Run with highest privileges”
Configure for: Windows 7, Windows Server 2008 R2

Server Restart General Tab

Server Restart General Tab

Triggers Tab
New…
Begin the task: On a schedule
Settings: Set your preferences. Be sure to select “Enabled” so it will run.
OK

Server Restart New Trigger

Server Restart New Trigger

Server Restart Triggers Tab

Server Restart Triggers Tab

Actions Tab
New…
Action: Start a Program
Program/script: C:WINDOWSsystem32shutdown.exe
Add arguments: -r /t 300 /c “This server will restart in 5 minutes. Save and Exit NOW!” /d p:1:1
Start in: c:windowssystem32
Note: /t 300 sets it to restart in 300 seconds, which is 5 minutes. Change the # of seconds to meet your needs, and update the server restart message to reflect the appropriate time.

Server Restart New Action

Server Restart New Action

Server Restart Action Tab

Server Restart Action Tab

Leave the rest of the tabs at default.

Today, I ma going to show you how to use task schedule to schedule auto shutdown or reboot server.

1.Login to Server and open Server Manager.

2.On the Server Manager, Click Tools and select Task Schedule.

3.On the Task Schedule, Select Task Schedule Library.

4.Right-click Task Schedule Library, select Create Basic Task.

5.On the Create Basic Task page, type Auto Shutdown in the Name filed, click Next.

6.On the Task Trigger page, select when do you want the Task to start, in my case is One time, click Next.

7.On the One Time page, select the start date and time, click Next.

8.On the Action page, select Start a program, click Next.

9.On the Start a Program page, type C:WindowsSysWOW64shutdown in Program/script filed, type -s -t 20 in Add arguments (optional) field, Here -s is for Shutdown, “-t” is for Timing and after that the seconds are given, if you would like to do reboot server not shutdown, you just need to change -s to -r, click Next.

10.On the Summary page, click Finish.

Hope you enjoy this post.

Cary Sun

Twitter: @SifuSun

Web Site: carysun.com

Blog Site: checkyourlogs.net

Blog Site: gooddealmart.com

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.

Понравилась статья? Поделить с друзьями:
  • Windows server storage spaces 4 диска powershell
  • Windows server std 2019 64b rus 1pk 16 core
  • Windows server std 2012 rus r2 oem
  • Windows server standard core 2019 лицензия
  • Windows server standard core 2019 16 corelic oei