Solved

add scheduled task via batch script

Posted on 2014-07-31
10
439 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
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 give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

863 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

23 Experts available now in Live!

Get 1:1 Help Now