9

What is a good way to reboot a list of windows computers on a windows domain? Assuming the windows domain controller does not have a service to do this, please make recomendations for a script.

Can I list the host names and iterate though the host names to send a restart command to each? Can I get a list of host names from the DHCP server running in a Windows 2008 box at the script's runtime?

My preferred scripting languages from most to least desirable are: PHP, javascript, Bash, Python (know very little), VB (know it but don't like it)

4
  • 8
    flip the breaker. I kid.
    – gravyface
    Oct 21, 2011 at 0:54
  • that would cause a shutdown, I need a reboot. Oct 21, 2011 at 3:38
  • @JM - not if they're set to "Resume previous power-state" in the BIOS.
    – Fake Name
    Oct 21, 2011 at 5:53
  • @Fake Name - that sounds like a lot of work Oct 21, 2011 at 6:26

4 Answers 4

15

If GPO isn't your thing, and you want to go with Mark Henderson's second option (batching shutdown /m) you can make your job easier by batch-jobbing the shutdown so it'll do them in parallel rather than serial. It requires PowerShell on the part of the admin station, but it's very nifty.

foreach ($ComputerName in $ComputerList) {
    invoke-command -AsJob -ScriptBlock {
        params($ComputerName)
        shutdown /m $ComputerName /r /f /t 0
    } -ArgumentList $ComputerName
}

What this fragment does is spawn as many background jobs executing in parallel as there are machines in $ComputerList. This can make shutting All The Things down happen a lot faster.

4
  • 2
    This is an interesting solution -- if you have alot of computers to reboot I would highly recomend this solution since it will run the shutdown commands in parallel. Oct 21, 2011 at 1:55
  • 2
    The -AsJob is the magic bit here.
    – jscott
    Oct 21, 2011 at 2:09
  • I'm curious why you're using the "shutdown" command rather than the Restart-Computer cmdlet. Jan 6, 2017 at 1:51
  • @CharlesBurge This was answered 5 years ago, and PS3 wasn't widely deployed. Also, this demonstrates the technique of running commands on other systems. In 2017, we'd just do it all in PowerShell and not bother with commands. Times change.
    – sysadmin1138
    Jan 6, 2017 at 15:01
8

You can do this with Group Policy Preferences by making a new scheduled task that will run every night at a certain time. The command for that task should be shutdown /r /t 0. You can then link that GPO to the OU or OUs that have your computers in them.

You will probably want to use the "Run This Program At a Random Interval" option set somewhere between 10-15 minutes. Having every single computer power up at the same time can be bad for your breakers if you're not careful. You might also want to check the option to only run the task if the computer has been idle for x hours, in case someone is pulling an all-nighter. You don't want to kill a whole night's worth of work by rebooting someone that's trying to make a deadline.

1
  • I am unfamiliar with setting Scheduled tasks with GPO, so i am wondering: if a machine is moved from one OU to another without the task defined, will the Shed Task disappear or will it remain after it is applied the first time?
    – MaCuban
    Jun 22, 2015 at 20:33
7

Two options:

  1. Create a scheduled task via GPO that runs shutdown /r /f /t 0 or shutdown /g /f /t 0 on each machine you want to reboot. (check out shutdown /? for more detail.

  2. Create a batch that runs shutdown /m [computer name] /r /f /t 0 from a central computer (perhaps the domain controller?). Loop it for each computer you want to reboot (change the [computer name]). This means that the computer will not be restarted if it is unreachable for whatever reason, and needs to be run from an account that has the rights to restart computers.

You should be able to write a batch file that loops through a list of computers pulled from the active directory and runs the command, however I don't have the time to write one today (and I'm not willing to test it even if I did write it, otherwise I would be grilled out for rebooting everyones computer in the middle of the day).

2
  • Additionally there is a psshutdown command that can run through a batch file as well, part of the sysinternals suite... Oct 21, 2011 at 1:28
  • I've used both 1 and 2. Now having fun with Powershell. If using #2, consider the main script spawning separate process for each computer (e.g. start cmd /c shutdown /m computer /r /f /t 0) or using some logic to check if online, else the delay for offline computers can be significant.
    – jscott
    Oct 21, 2011 at 2:08
4

The best way to do that is to fire the person having the idea that this is needed and the doing what all other people do - not do that.

7
  • The folder redirection seems to be tying up resources when people stay logged in overnight. I suppose I could try to set up a mass logout instead of a mass reboot, but rebooting seems to clear up so many problems. People go weeks or months without rebooting. I usually don't invest lots of time to learn the right way to run windows systems because it's not my primary job. What do you recommend? Oct 21, 2011 at 5:30
  • 1
    Ah - no. Tons of companies do not require their people to reboiot - you think they neve use folder redirection? I suggest fixing the issue at hand. I personally would be pissed if I would be logged out of my workstation every day - I often let jobs run overnight. Your laziness may cost lot of people hardship - do your job properly or hire someone who does.
    – TomTom
    Oct 21, 2011 at 5:42
  • Well, doing my job properly means not spending too much time babying our little windows system. Oct 21, 2011 at 6:28
  • Not knowing what you do? ;) I fire people saying they are incompetent ni their job, regardless how their performance is.
    – TomTom
    Oct 21, 2011 at 11:16
  • Sysadmin is a side job I do for my family to help them out. If I had infinite time sure, I would read more books on windows and other tangents. But my best way to make money is to stick to web software. I think you answer was not at all in the spirit of offering a technical solution to the question I asked. Oct 21, 2011 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .