Link to home
Start Free TrialLog in
Avatar of joukiejouk
joukiejouk

asked on

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?
SOLUTION
Avatar of Rezwan Islam
Rezwan Islam
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

check the below links :-

http://goo.gl/dVebg0

http://goo.gl/atGZRz

Bahloul.
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
Avatar of joukiejouk
joukiejouk

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm still confused. Please help me write a script for this. H
2015-01-22-10-28-32.png
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.
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

what does "dotheshit" text mean? Is that really what I am putting in?
See my revised code.
BTW, what Windows version are you running?
Windows 7. Sorry to be so ignorant, but i am a novice to scripting and doing mass deployment of something.
No worries. Glad to help.
I get this error (attached) when I execute it as admin.


User generated image
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

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.
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"
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.

User generated image
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
@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.
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?
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?
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?
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?
I see you have a similar question here: https://www.experts-exchange.com/questions/28603389/How-do-I-configure-GPO-on-a-Server-2008-DC-to-set-a-task-scheduler-to-restart-computers-in-a-specific-OU.html

Are these related? Or, are you seeking 2 different solutions? It looks like you are going with the GPO solution there, instead.
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:
https://www.experts-exchange.com/questions/28604463/What-command-should-I-execute-to-have-PSEXEC-initiate-a-GPUPDATE-for-400-remote-machines.html
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.
@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?
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"
Would the SvcShutdnWkstns domain account need to be a member of domain admin group in order for it to work?