Solved

add scheduled task via batch script

Posted on 2014-07-31
10
456 Views
Last Modified: 2014-09-15
Greetings Experts.  Routinely I need to restart a handful of computers out of the 250 in the environment.  One solution I thought up was to add a scheduled task to the computers listed in a text file which would restart the computer at the time I specified.  

For this to work, I would need to have (A) a batch script that would add the computers listed in (B) the text file.  I need your help with A and B.  I'm not familiar with other scripting languages so please stick with batch files.  If you have a different suggestion on achieving the same result (scheduling pc's in a list to restart at x time), feel free to offer it up along with the necessary scripts.  

Thanks in advance for your time.
0
Comment
Question by:samiam41
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 70

Expert Comment

by:Qlemo
ID: 40231957
@echo off
set MinutesToWait=30

set /A secs=MinutesToWait*60
for /F "delims=" %%C in (C:\Scripts\RestartPCs.txt) do shutdown /m \\%%C /r /f /t %secs% /c "Administrative maintenance"

Open in new window

would initiate a shutdown in 30 minutes for all machines listed in the text file C:\Scripts\RestartPCs.txt.
Another way is to create a scheduled task with schtask with runonce and delete after execution, but the only pro of that approach is that you can set up an exact point in time instead of "x minutes in the future".
0
 
LVL 55

Assisted Solution

by:McKnife
McKnife earned 100 total points
ID: 40232735
There are active directory mmc add-ins that can restart/shutdown whole OUs/groups. Free one: http://www.specopssoft.com/products/specops-gpupdate
Screenshot
0
 
LVL 25

Accepted Solution

by:
Lionel MM earned 200 total points
ID: 40234306
I use this site to help me create my schedules tasks
http://technet.microsoft.com/en-us/library/bb490996.aspx
for /F "tokens=1 delims=," %%i in (C:\PCList.csv) do schtasks /create /tn TaskName /tr "Shutdown -f -r -t 10" TaskRun /st TimeYouSpecify /s computerName or IP Address /u domain\userName /p password

You may have to replace /tr "Shutdown -f -r -t 10" with a batch file for example /tr C:\utils\RestartPCs.Bat
if so make a simple batch file with this in it
Shutdown -f -r -t 10
-f = force restart -r = restart -t is time in seconds
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 9

Author Comment

by:samiam41
ID: 40267717
Thanks experts for your suggestions.  Testing them now and will update shortly.
0
 
LVL 59

Expert Comment

by:LeeTutor
ID: 40321598
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0
 
LVL 25

Expert Comment

by:Lionel MM
ID: 40317440
I don't normally object to these closings by ID: 40234306 is exactly what he asked for and he said he will get back to us and I know this works as I have tested and use it myself.
0
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 200 total points
ID: 40317634
The issue with http:#a40234306 is that it is incomplete:
missing the (required)  /sc once   option
not showing the time portion format of  /st  (needs military time, i.e. 24 hrs)
missing the /Z switch to delete the task after execution.
That you also wrote "You may have to replace" tells us that you did not use that script yourself, else you would know. The answer is: you should not need to use a batch here.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40321599
Objection: With my additions in http:#a40317634 the code in http:#a40234306 is the best answer one can get for a common task, so I suggest accepting both comments instead of deleting.
0
 
LVL 9

Author Comment

by:samiam41
ID: 40322872
Sorry everyone.  I was out longer than I expected.

To help close this out, here is what I found so far:

McKnife 2014-07-31 at 15:00:31 ID: 40232735- Good option and allows for restarts/shutdowns using the ADUC MMC.  Unless I did it wrong, I didn't see where I could schedule the restart to be at x time.  

lionelmm 2014-08-01 at 09:21:07 ID: 40234306- A keeper that I will use going forward along with the modifications made by Qlemo 2014-09-11 at 12:41:10 ID: 40317634

I appreciate everyone's time with this and apologize again for the delay in responding/closing out.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
On some Windows 7 (SP1) computers, Windows Update becomes super slow even the computer is reasonably fast.  There's one solution that seemed to have worked well for me (after trying a few other suggested solutions).
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question