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

Posted on 2009-03-29
Medium Priority
Last Modified: 2012-05-06

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
Question by:satish_halemani
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
LVL 70

Expert Comment

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


Author Comment

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).
LVL 70

Expert Comment

ID: 24080642
You have to press enter after your input, and you have to provide a list of servers in servers.txt.
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!


Author Comment

ID: 24121008

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.
LVL 70

Accepted Solution

Qlemo earned 1000 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.

Author Comment

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.
LVL 70

Expert Comment

ID: 24417463
Any results yet?

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

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…
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.

771 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