Rebooting multiple servers as same time via PowerShell?

We want to reboot 30+ servers at the same time.  This heart of the matter comes down to this script.

get-content c:\Servers.txt | %{Restart-computer –computername $_ –force}

 

But is using PowerShell really a good solution to the problem?  I don't know what version of Powershell (if any) is  running on each remote server, what firewall issues we may encounter, either.  I need a "rock solid" approach that does the job and hopefully spares me from needing to setup a "reboot" script on each individual server.

TIA,

Barkingdog

 


August 22nd, 2011 5:11pm

Restart-computer doesn't rely on Powershell running on the remote computer.  I believe it does require an RPC connection to the remote system, so the firewall may be an issue. 

Your choices will be dictated by the firewall more than anytihng else.  I'd find out exactly what that situation is first.

Free Windows Admin Tool Kit Click here and download it now
August 22nd, 2011 5:33pm

I'd just use a batch file, with 30+ lines like:

shutdown /r /f /m \\s

August 22nd, 2011 5:51pm

I'd just use a batch file, with 30+ lines like:

shutdown /r /f /m \\s

Free Windows Admin Tool Kit Click here and download it now
August 22nd, 2011 11:43pm

Could also use WMI to reboot the servers, provided you are running this script with an account that has access to reboot the server. Otherwise use -credential to specify admin account.

$server = get-content c:\Servers.txt

(gwmi -Class Win32_OperatingSystem -ComputerName $server).Win32Shutdown(6)
If ($?) {
Write-Host "$server successfully rebooted"
}Else{
Write-Host "Could not reboot $server"
}


  • Marked as answer by Tiger Li Monday, August 29, 2011 2:24 AM
August 23rd, 2011 6:08am

If you prefer a GUI to verify that all of them receive the command and you have the correct settings, try this:

 

shutdown /i

It's a more user-friendly shutdown/restart experience.

Free Windows Admin Tool Kit Click here and download it now
August 23rd, 2011 6:30am

Does the powershell -FORCE option KILL running services or just stops them ? The only thing in ps help is that it shuts down immediate' ...   

Does immediate mean 'kill all running processes including services' or rather kill all running processes BUT services' ?

I do a reboot and check if they come online again, then check for specific services, write this in a database and mail a ssrs repport to myself !

April 25th, 2012 11:19am

Shutdown /f will attempt to close all programs and stop all services gracefully.  If any of these do not respond, it will "kill" them.
Free Windows Admin Tool Kit Click here and download it now
April 25th, 2012 11:24am

shutdown -r -m \\server -f -t 0   thats what I use to reboot my servers.   -r reboot -m machine -f forace -t count down timer    
April 25th, 2012 12:54pm

If you know the servers are logged off, there shouldn't be a need for the -f, but there's no harm in including it.  Or is there?  Maybe some critical process is running that could be completely messed up if you just force a reboot. (Such as a backup, for example)

Free Windows Admin Tool Kit Click here and download it now
April 25th, 2012 1:10pm

well, my view is if you are rebooting a server (which is all I reboot) then its something that has to happen now (problem or scheduled) and those processes need to end. a reboot of a server can take 10-15 min if its got storage attached to it (almost all of mine does) so when I need a system back online because of an application issue, or when I have been given 30 min to complete some work, I need it rebooted ASAP..   if its a workstation, screw them, its only a workstation lol :)    
April 25th, 2012 1:21pm

I think this is good as well as I've searched for a Powershell script to do this and can't find anything good.

What I need to do though is put in a check for a service to confirm it's started, then send an email.

Can anyone help me?

Free Windows Admin Tool Kit Click here and download it now
April 10th, 2014 2:26am

Thanks for this script, it works great!
  • Edited by ThePCDr 1 hour 56 minutes ago
April 12th, 2015 1:11am

Thanks for this script, it works great!
  • Edited by ThePCDr 1 hour 49 minutes ago
Free Windows Admin Tool Kit Click here and download it now
April 12th, 2015 1:15am

Thanks for this script, it works great!
  • Edited by ThePCDr Sunday, April 12, 2015 5:10 AM
April 12th, 2015 5:10am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics