Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2009-03-29
8
1,902 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:satish_halemani
  • 4
  • 3
8 Comments
 
LVL 69

Expert Comment

by:Qlemo
ID: 24020161
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

0
 

Author Comment

by:satish_halemani
ID: 24074924
This is not working. Though it opens the command prompt, it doesn't respond whether i type S or any other key(for reboot).
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 24080642
You have to press enter after your input, and you have to provide a list of servers in servers.txt.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:satish_halemani
ID: 24121008
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.
0
 
LVL 69

Accepted Solution

by:
Qlemo earned 250 total points
ID: 24121336
Most probably you are executing the script on Windows 2000, where no shutdown command exists. Starting with XP, the syntax of shutdown allows for the options I used above (target system is no issue here, only the client which runs the script).

For debug, you should remove the    start /min   part of the last line. This will a) show the command output  b) wait for the execution of the command.

With start command, all shutdowns are issued at the same time in parallel, running each command in an own command window. I suppose the window is closed immediatly because of a syntax error.
0
 

Author Comment

by:satish_halemani
ID: 24128484
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.
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 24417463
Any results yet?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question