Solved

add scheduled task via batch script

Posted on 2014-07-31
10
437 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 68

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 53

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:
lionelmm 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
 
LVL 9

Author Comment

by:samiam41
ID: 40267717
Thanks experts for your suggestions.  Testing them now and will update shortly.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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:lionelmm
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 68

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 68

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ZIP or ZIPX 8 70
Event ID: 5719 / Source: NETLOGON 9 56
windbg taking it's time 32 51
print logs windows 7 3 35
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
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 the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now