Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

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

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
joukiejouk
Asked:
joukiejouk
  • 14
  • 11
  • 2
  • +2
2 Solutions
 
Rezwan IslamSystems AdministratorCommented:
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
 
BahloulCommented:
Hi,

check the below links :-

http://goo.gl/dVebg0

http://goo.gl/atGZRz

Bahloul.
0
 
donciakasCommented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
joukiejoukAuthor Commented:
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
 
NVITCommented:
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
 
joukiejoukAuthor Commented:
I'm still confused. Please help me write a script for this. H
2015-01-22-10-28-32.png
0
 
joukiejoukAuthor Commented:
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
 
NVITCommented:
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
 
joukiejoukAuthor Commented:
what does "dotheshit" text mean? Is that really what I am putting in?
0
 
NVITCommented:
See my revised code.
BTW, what Windows version are you running?
0
 
joukiejoukAuthor Commented:
Windows 7. Sorry to be so ignorant, but i am a novice to scripting and doing mass deployment of something.
0
 
NVITCommented:
No worries. Glad to help.
0
 
joukiejoukAuthor Commented:
I get this error (attached) when I execute it as admin.


2015-01-22-13-48-28.png
0
 
NVITCommented:
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
 
joukiejoukAuthor Commented:
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
 
NVITCommented:
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
 
joukiejoukAuthor Commented:
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
 
NVITCommented:
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
 
Rezwan IslamSystems AdministratorCommented:
@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
 
joukiejoukAuthor Commented:
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
 
NVITCommented:
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
 
joukiejoukAuthor Commented:
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
 
joukiejoukAuthor Commented:
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
 
NVITCommented:
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
 
joukiejoukAuthor Commented:
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
 
NVITCommented:
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
 
joukiejoukAuthor Commented:
@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
 
NVITCommented:
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
 
joukiejoukAuthor Commented:
Would the SvcShutdnWkstns domain account need to be a member of domain admin group in order for it to work?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 14
  • 11
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now