Solved

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

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

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 68

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 68

Expert Comment

by:Qlemo
ID: 24417463
Any results yet?
0

Featured Post

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.

910 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

21 Experts available now in Live!

Get 1:1 Help Now