Link to home
Start Free TrialLog in
Avatar of MRS
MRSFlag for United States of America

asked on

Windows 7 64bit daily reboot

I need to create a script for daily reboot on all Windows 7 64bit PC's. What is the best way to do this?
If you do it via Group Policy Schedule Tasks, it is not creating ST on PC's. If you do it as Startup script to create ST via GP it is still not doing it. Here is the command I use to create .bat file and then put this in GP under Startup scripts:
"schtasks.exe /create /SC DAILY /TN reboot /TR "C:\windows\system32\shutdown.exe -f -r -t 00" /ST 02:00"
I did verified and it creates task when run locally so script is ok.
I am not sure what am I missing? Even if it was doing it via ST, I do not think this would be the best way to handle this because, what about PC's that none logs onto but you still want them to reboot daily regardless?
Avatar of Darr247
Darr247
Flag of United States of America image

It's probably not being created because the user that logs on doesn't have sufficient permission/access to create a scheduled task (only Admin-level users can create scheduled tasks).  I think you also must specify a /p [password] when creating a ST like that, unless you also use /ru System to make it run with System permissions/security.


Could you use the Request Attention link to ask the admins here to add the appropriate server OS as an additional topic area?   That should be sure to get the attention of experts that monitor those specific topic areas.
Avatar of MRS

ASKER

I have admin right on every pc (part of admin group), so by me creating task, not sure why is it not accepting it via GP. Again if I run this script locally and check my ST it is there.
Sure. I will ask admins to add a topic. Thanks.
Well, technically you can't ever have a script that insures that the system will always reboot if somebody is logged on.

That is due to the possibility that some of the services running will fail to stop because an application is running that uses them and shutdown triggers one of those are-you-sure things.

So to tackle the problem you must make sure you have policy that people log off, and even then you need to allow for the program not working because of resources.

I know this isn't a solution for you, but you need to consider that no matter what you script it will not be infallible.

To insure a shutdown, you need to have some sort of a watchdog timer or  board in the computer.
I'd probably set up a scheduled task from another machine to handle this.   I'd create a list of those machines, and pipe it into a for command.

for /f %f in (computers.txt) do shutdown /r /t 0 /f /m \\%f

You can create your computers.txt by an automation script.  The only key of course would be making sure you only got the machines you wanted.  I'm sure it could be done fairly easily in powershell.  If you had them separated into their own OU, it'd be simple.
get-adcomputer -filter * -searchbase "ou=x64computers,dc=domain,dc=local 

Open in new window


I'm sure it could be done with dsquery also, but it'd probably be trickier.

By doing all of this from a separate machine, you shouldn't have much trouble making it work, and even if they are logged in, it will be forced off.

Coralon
Avatar of MRS

ASKER

@Coralon
This might work but only thing is that WinRM service has to run on each PC. How do you ensure that WinRm is running on 500+ PC's or not running and if not running how to start it remotely?
Avatar of MRS

ASKER

I think I will use PsExec. So I will create powershell script that resides on server and that  will call PsExec from server and feed list of PC names. Once I connect to their cmd.exe just run shutdown -r -f -t 00 command and that's it. It should work as a charm regardless of the OS type or version or architecture. Simple and powerful. Will work on it today and let you know if doable or not.
ASKER CERTIFIED SOLUTION
Avatar of MRS
MRS
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
Avatar of MRS

ASKER

Considering that all PC's have C:\reboot.bat do  PowerShell script with:
Get-content c:\test.txt | foreach {
\\"ComputerName"\Sysinternals\PSTools\psexec.exe \\$_ c:\reboot.bat
Avatar of MRS

ASKER

Because it is the only solution that works well without considering architecture of the PC and simplest one.