• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

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?
1 Solution
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.
MRSAuthor Commented:
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.
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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.

MRSAuthor Commented:
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?
MRSAuthor Commented:
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.
MRSAuthor Commented:
Ok I did this. Sometimes simple solutions work well:

Create reboot.bat file on each PC on root drive with line "shutdown -r -f -t 00"

Create PowerShell script with lines:

$compname = Get-content c:\list.txt
\\"PCName"\Sysinternals\PSTools\psexec.exe \\$compname c:\reboot.bat

"PCname"=path where psexec.exe resides
(I can also query AD for list of PC's instead feed them as txt file, as we have them in separate OU)
This way we have a reboot process and just run it every night in Schedule Task.
Simple isn't it!
MRSAuthor Commented:
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
MRSAuthor Commented:
Because it is the only solution that works well without considering architecture of the PC and simplest one.
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: 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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now