Solved

add scheduled task via batch script

Posted on 2014-07-31
10
444 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
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 69

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 54

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 24

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 24

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 69

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 69

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
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 …
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.

773 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