Solved

How can i push out a scheduled task to reboot PCs daily at a certain time to all computers on my network?

Posted on 2015-01-21
29
249 Views
Last Modified: 2015-02-14
I scheduled a task to reboot a PC daily at a certain time. Now I need to push this same task to all 300 computers on my network. Is  there a tool/command/script that I can use to achieve this? Can PSEXEC do this? If so, can someone please provide instruction to do so?

A large number of computers on the network already have this scheduled task, but I learned that whoever set it up did not input the right parameters, therefore causing the scheduled task to fail. I fixed it and want to deploy it. The question is, if I do use a tool/script/command, or whatever, can it overwrite the existing scheduled task and put in place the corrected one?
0
Comment
Question by:joukiejouk
  • 14
  • 11
  • 2
  • +2
29 Comments
 
LVL 3

Assisted Solution

by:Rezwan Islam
Rezwan Islam earned 100 total points
ID: 40563653
You can write a batch file for this. Yes you should be able to achieve that using PSEXEC.
-----------------------
@echo off
call :dotheshit machine1
call :dotheshit machine2
call :dotheshit machine3
call :dotheshit machine4
.
.
call :dotheshit machine300

GOTO endtask

:dotheshit

psexec \\%1 -i -s c:\windows\system32\shutdown.exe -r -t 0

GOTO nothing
:endtask

pause
:nothing

-------------

Create a schedule task that calls this batch file, give it a different name than the old one and if it is hard to find out the previous "unreliable" scheduled task but you know when it runs at least, then set this new task at a later time.

There are lots of other ways to do it too.
0
 
LVL 3

Expert Comment

by:Bahloul
ID: 40563664
Hi,

check the below links :-

http://goo.gl/dVebg0

http://goo.gl/atGZRz

Bahloul.
0
 
LVL 3

Expert Comment

by:donciakas
ID: 40563719
Here is a step-by-step guide how to apply scheduled tasks to comptuters on active directory adding it via GPO

Applies To: Windows 8, Windows Server 2008 R2, Windows Server 2012

https://technet.microsoft.com/en-us/library/cc725745.aspx


a bat or cmd script should contain restart command:
shutdown -r -t 00 

Open in new window


additionaly you might want to add force
-f

Open in new window

flag to force restart closing all apps for all users
0
 

Author Comment

by:joukiejouk
ID: 40564157
I need a step-by-step guide, as I am not to familiar with GPO or PSEXEC. Let's just keep this as simple as possible. Lets just create a bat or cmd script to execute this. Can someone please provide instructions? Lets say I have 2 computers that I want to use to initiate this. The two computers are 1. Testpc1 and 2. Testpc2. How would I write the bat script for this, and have it run the reboot daily at 5am? Then, how would I execute the command with PSEXEC to push it to these two computers? It is important that the script to force restart closing all apps for all users. Please help provide step-by-step instructions using the example i provided. Thank you.
0
 
LVL 23

Accepted Solution

by:
NVIT earned 400 total points
ID: 40564492
Using Rezwan's example...
Note:
- This solutions runs from one computer. It does not use a scheduled task.
- To run it daily, call it from a scheduled task.
- I used AT instead of psexec because I'm not sure if psexec has a switch to run it at a certain time.
@echo off
 call :dotheshit Testpc1
 call :dotheshit Testpc2

 GOTO endtask

 :dotheshit
at \\%1 05:00 shutdown.exe -r -f

 GOTO nothing
 :endtask

 pause
 :nothing

Open in new window

0
 

Author Comment

by:joukiejouk
ID: 40564762
I'm still confused. Please help me write a script for this. H
2015-01-22-10-28-32.png
0
 

Author Comment

by:joukiejouk
ID: 40564763
If you can simply help me write a script, and provide instructions on how to call it so it can be executed, that would be great. Sorry, I am a novice to things like this. Maybe a video would help.
0
 
LVL 23

Expert Comment

by:NVIT
ID: 40564788
CALL line goes to the dotheshit line, which runs the AT line with Testpc1

Next, it goes to the nothing line, i.e. the end of the file, where nothing happens, which returns to the top to run the next CALL for Testpc2.

You could remove the :endtask line and PAUSE. I think it's there for debugging purposes.

My last post withe the code could be saved to a file such as ShutdownPCs.bat. Save the file to a folder that is searchable by the PATH environment variable. If not, you have to hard-code the folder name when it is run.

Let's says you save it to folder c:\utils.

Open a CMD prompt.

Type c:\utils\ShutdownPCs.bat

It should run.

Here's a reduced version:
@echo off
call :DoIt Testpc1
call :DoIt Testpc2
goto nothing

:DoIt
at \\%1 05:00 shutdown.exe -r -f
goto nothing

:nothing

Open in new window

0
 

Author Comment

by:joukiejouk
ID: 40564806
what does "dotheshit" text mean? Is that really what I am putting in?
0
 
LVL 23

Expert Comment

by:NVIT
ID: 40564807
See my revised code.
BTW, what Windows version are you running?
0
 

Author Comment

by:joukiejouk
ID: 40564842
Windows 7. Sorry to be so ignorant, but i am a novice to scripting and doing mass deployment of something.
0
 
LVL 23

Expert Comment

by:NVIT
ID: 40564862
No worries. Glad to help.
0
 

Author Comment

by:joukiejouk
ID: 40565330
I get this error (attached) when I execute it as admin.


2015-01-22-13-48-28.png
0
 
LVL 23

Expert Comment

by:NVIT
ID: 40565402
psshutdown might be simpler https://technet.microsoft.com/en-us/sysinternals/bb897541.aspx:
@echo off
call :DoIt Testpc1
call :DoIt Testpc2
goto nothing

:DoIt
psshutdown.exe -t 05:00 -r -f \\%1
goto nothing

:nothing

Open in new window

0
What Security Threats Are You Missing?

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.

 

Author Comment

by:joukiejouk
ID: 40565434
Couple of questions.

1. The time in the code, do I need to specify military time or AM or PM (e.g. - 5:00 PM, or 17:00)?
2. Secondly, all these systems i will be rebooting have a specific account (e.g. - abc\user1 with the password as password1)

So, just to be clear, this script that I am running will be ran from a local machine right? Will running this script create a scheduled task to do the daily reboot for testpc1 and testpc2? Or, do I have to run this manually each time in order for testpc1 and testpc2 to reboot?

Can you please use my example to put in a script? Thank you.
0
 
LVL 23

Expert Comment

by:NVIT
ID: 40565507
1. military time. 5 am would be 05:00. 5 pm would be 17:00
2. If they all have the same account then change psshutdown as:
psshutdown.exe -u abc\user1 -p password -t 05:00 -r -f \\%1

Open in new window


Yes. Runs from a single (local) machine. It could be a workstation or server.

I would make a scheduled task on the machine.

Open Task Scheduler...
Create Basic task.
Name: Reboot PCs
Description: Reboot clients
Trigger: Daily (or whatever you want)
Action: Start a program
Program: cmd.exe
Add arguments: /c c:\utils\ShutdownPCs.bat
Start in: c:\utils

On Finish tab, pick checkmark in "Open Properties dialog..". A new windows shows.
In General tab, put check in "Run with highest privileges"
0
 

Author Comment

by:joukiejouk
ID: 40565555
Thanks for the psshutdown script, that worked as far as initiating the reboot for the remote machines. Now I have a question about scheduling the scheduled task. I am currently testing this is my lab. By the way, you been very helpful, and I am succeeding and learning alot from your method. I thank you for that.

Please see screenshot. I have a question about credentials on the schedule task on initiated from the server, and a question about the time for reboot.

Scheduler
0
 
LVL 23

Expert Comment

by:NVIT
ID: 40565592
Hi joukiejouk...

Thank you for the compliment. I'm glad you are learning.

Yes, change it to domain admin account.

Yes. Since you will run the task at 4 PM, you can remove the -t 16:00
0
 
LVL 3

Expert Comment

by:Rezwan Islam
ID: 40565673
@NewVillageIT - I actually recommended to put the script in a batch file and call that batch file from a schedule task and set time triggers on that schedule task for any schedule you like. It does use a schedule task.

@joukiejouk - Isn't the idea of managing better is centralizing things properly. Why would you put a schedule task on every single machine when you can manage it from a single server/workstation. You can even generate a output log file to see which one failed to restart. Good luck.
0
 

Author Comment

by:joukiejouk
ID: 40566780
Found out that the user1 account is an account not on the domain (abc), but rather just a local admin account with administrative privileges for all 500 remote computers. So, if I need to change the script, how should I apply it?

Here's the original:
psshutdown.exe -u abc\user1 -p password -t 05:00 -r -f \\%1

Should it be changed to:
psshutdown.exe -u .\user1 -p password -t 05:00 -r -f \\%1


Also, we are talking 500 remote machines here, and some are in different time zone. Do you see a problem executing this script one one centralized server, or should scheduled task be applied to all 500 remote computers instead? If so, how would I create a script for that and push the scheduled task script for all 500 remote machines?
0
 
LVL 23

Expert Comment

by:NVIT
ID: 40567199
You need a domain admin to play a role in this solution of yours.
To push the tasks, you could use the GPO solution suggested earlier by donciakas.

Are these computers part of a domain you have access to?
0
 

Author Comment

by:joukiejouk
ID: 40568401
Yes these computers are part of a domain i have access to.  I think GPO would be the preferred method because we are talking about 500 machines here. Beside GPO, is there a way to have a scheduled task added to all the machines? Like say I create a scheduled task, can I copy that same scheduled task and push it to all 500 machines using psexec?
0
 

Author Comment

by:joukiejouk
ID: 40572027
What would happen when the script execute for 400 machines, and for some reason it stops because maybe a machine does not ping? Would it halt the scheduled task? Does the script execute rapidly so that it will execute to all 400 machines at 5 am? Do you see any issues with running this script to execute for 400 machines? Will it hose the server that holds the scheduled task to execute the script?
0
 
LVL 23

Expert Comment

by:NVIT
ID: 40572110
I see you have a similar question here: http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2008/Q_28603389.html

Are these related? Or, are you seeking 2 different solutions? It looks like you are going with the GPO solution there, instead.
0
 

Author Comment

by:joukiejouk
ID: 40572116
Yes, It's two different questions.

I posted another question as well, and maybe since you know my situation, you can answer that to get points. I will definitely give you points on this thread.

New question:
http://www.experts-exchange.com/Software/System_Utilities/Remote_Access/Q_28604463.html
0
 
LVL 23

Expert Comment

by:NVIT
ID: 40572155
for some reason it stops because maybe a machine does not ping?
After a few seconds, I don't know the exact number, psshutdown does the next station.

Would it halt the scheduled task?
It shouldn't

Does the script execute rapidly so that it will execute to all 400 machines at 5 am?
In your specific case, I don't know how long it takes to reach 1 computer from the server so don't know a safe number to use. On a LAN, assume 1-2 seconds to send the command to each computer, assuming each is responsive.

Do you see any issues with running this script to execute for 400 machines?
At worst, some computers will be unresponsive. Is assuming 20%, or 80 too high? At 1 minute per computer until psshutdown goes to the next, that 80 minutes. For that, set the task's Trigger, "Stop any task that runs longer than" option to around 2 hours.

Will it hose the server?
Do you mean hangs it so it affects other server functions? I don't think it should come to that. Of course, no guarantees. Still, I've never seen it hang a server.
0
 

Author Comment

by:joukiejouk
ID: 40596545
@NewVillageIT:

If I wanted to run a account other than my domain admin account, should i use a service account instead? That way it can be set to never change the password, because every so often, I need to change my password on my domain admin account. Also, can this service account be a local account, or does it have to be a service account on the domain? If it has to be a service account on the domain, does it have to be part of the domain admin group?
0
 
LVL 23

Expert Comment

by:NVIT
ID: 40596988
If you are talking about the built-in system account, I don't think there is a domain version that can be used on each station. I would...

- Make a domain user account specific to this use. Name it something like SvcShutdnWkstns.
- Give it a strong password.
- Set the "Password does not expire", and "User cannot change password"
0
 

Author Comment

by:joukiejouk
ID: 40597074
Would the SvcShutdnWkstns domain account need to be a member of domain admin group in order for it to work?
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
Resolve DNS query failed errors for Exchange
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

22 Experts available now in Live!

Get 1:1 Help Now