Solved

add scheduled task via batch script

Posted on 2014-07-31
10
454 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

734 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