Link to home
Start Free TrialLog in
Avatar of satish_halemani
satish_halemani

asked on

Batch file or powershell script ro remotely shutdown/restart windows servers

Hi,

I need a batch file or a powershell script which i can use to remotely shutdown or restart multiple windows servers. When i execute the script, it should give me he option of where servers need to be shutdown or restarted which i can accordingly choose. We have windows 2000/2003/2008 servers in our environment.

Any help would be much appreciated.

Thanks in advance
Avatar of Qlemo
Qlemo
Flag of Germany image

The following script will give "Planned, Other reason" as reason for shutdown/reboot. A grace period of 5 seconds is set up, and all servers are shutdown at the same time. It requires to have the same admin credentials on each machine.


@echo off
set /P reboot=type s to shutdown only, anything else to reboot
if not defined reboot set reboot=/r
if %reboot% == s (set reboot=/s) else (set reboot=/r)
 
for /F %%C in (servers.txt) do start /min shutdown /m \\%%C /t 5 /d p:0:0

Open in new window

Avatar of satish_halemani
satish_halemani

ASKER

This is not working. Though it opens the command prompt, it doesn't respond whether i type S or any other key(for reboot).
You have to press enter after your input, and you have to provide a list of servers in servers.txt.
Qlemo,

No luck. After providing input and press enter, there is no response at all and all the server names are there in servers.txt. Not sure what's the issue. I am executing the script from a windows 2003 server.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany 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
I used the script on a windows 2003 server only as we dont have 2000 servers in our domain.

Let me try it again with your new suggestions and see if it works.
Any results yet?