Solved

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

Posted on 2009-03-29
8
1,906 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
[X]
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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
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.

730 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