Solved

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

Posted on 2009-03-29
8
1,892 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 68

Expert Comment

by:Qlemo
Comment Utility
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
Comment Utility
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 68

Expert Comment

by:Qlemo
Comment Utility
You have to press enter after your input, and you have to provide a list of servers in servers.txt.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:satish_halemani
Comment Utility
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 68

Accepted Solution

by:
Qlemo earned 250 total points
Comment Utility
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
Comment Utility
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 68

Expert Comment

by:Qlemo
Comment Utility
Any results yet?
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Sometimes a user will call me frantically, explaining that something has gone wrong and they have tried everything (read - they have messed it up more and now need someone to clean up) and it still does no good, can I help them?!  Usually the standa…
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now