A good way to reboot all computers on a Windows domain each night
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)
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.
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.
Two options:
Create a scheduled task via GPO that runs
shutdown /r /f /t 0
orshutdown /g /f /t 0
on each machine you want to reboot. (check outshutdown /?
for more detail.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).
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.