VBScript to Shutdown Remote Windows 2003 Servers

I am a domain admin for a large enterprise environment.  We are moving our data center and I need a script to shutdown Windows 2000 and 2003 servers remotely.  Since some of the servers will need to be taken down prior to the bulk and some after the bulk I would like to find a vbscript that will allow me to use a txt file to list which servers I want the shutdown command to run on.  
I usually create a batch file to run the VBScript so it will run in a DOS window instead of issuing pop-up messages.  I have approx 500 servers I will need to shut down.  I honestly do not want to have to create a messy batch file to issue the shutdown /m \\computername code for all 500 servers.  That would take way to long.  If someone can help me I would really appreciate it.

Thanks,
Scott
DrScott35Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
paul-adamConnect With a Mentor Commented:
Heres another option which allows you to specify user name and password of the user which will issue the shutdown command

Curteousy of a technet magazine article (I forget the author - if your reading this...sorry!)
==========================================
Dim oFSO, oTS, sClient, oWindows, oLocator, oConnection, oSys
Dim sUser, sPassword

'set remote credentials
sUser = "Administrator"
sPassword = "password"

'open list of client names
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTS = oFSO.OpenTextFile("C:\clients.txt")

Do Until oTS.AtEndOfStream
 
 'get next client name
 sClient = oTS.ReadLine
 
 'get WMI locator
 Set oLocator = CreateObject("WbemScripting.SWbemLocator")

 'Connect to remote WMI
 Set oConnection = oLocator.ConnectServer(sClient, _
   "root\cimv2", sUser, sPassword)

  'issue shutdown to OS
 ' 4 = force logoff
 ' 5 = force shutdown
 ' 6 = force rebooot
 ' 12 = force power off
 Set oWindows = oConnection.ExecQuery("Select " & _
   "Name From Win32_OperatingSystem")
 For Each oSys In oWindows
   oSys.Win32ShutDown(5)
 Next

Loop

'close the text file
oTS.Close
WScript.Echo "All done!"
===============================================
0
 
hlarseCommented:
Here's a batch file which take a text file input.
http://www.atomicmpc.com.au/forums.asp?s=2&c=10&t=4434
0
 
DrScott35Author Commented:
The script works however, I do not like having to save my Domain Admin Password in a Clear Text text file.  Is there a way I can run this using my logged in credentials?  Also, I would like to have it dispaly which server it is attempting to shutdown for example:

Scobydoo
Mickeymouse
DonaldDuck
All Done!
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
paul-adamCommented:
Thats fair enough - My scripting abilities arent the best (like I said - thats simply copied from a technet article from a good few years ago)

One option could be to create a non-"domain admin" user that has rights to shutdown computers...But of course there is an inherant security risk with that too.

But it should be relatively easy to rework and just use the credentials of the currently logged on user (i.e. you when you run the script)

And all we would need to do is simply echo to screen which server it is currently doing - although, its a vbs script so would run very fast, and just issue all of the shutdown commands to every server in the list in one go, so all you would get is a repeat of the servers in your text file.
Im guessing you would prefer it to echo out wether the server has accepted the command or not?

I'll go and have a dig about on the net to see what I can find - but Im sure someone else may come up with the goods first ;)

Cheers

Paul
0
 
tigermattCommented:
How about the ShutdownRestart tool? http://redmondmag.com/columns/article.asp?EditorialsID=1385

You can target all the machines in an OU, text file or list using this quite easily and force to shutdown, restart, logoff and power-off remotely.

Have a look.
0
 
DrScott35Author Commented:
Tigermatt,

Thanks for the article.  The link to download the program did not work inside the article but after doing a little web searching I was able to find the correct script.  Here's the address for anyone that follows:  http://www.computerperformance.co.uk/ezine/BestPractice/BestPractice97.htm .  I have not tested it since I'm just going to use the before mentioned code.  I did some tweaking to it this afternoon.  
If it works the way the article describes I'm sure it would be a very useful utility.
Thanks!
0
 
DrScott35Author Commented:
Thank you for your help Paul.  I'm going to use this script for now but I'm still looking for a better alternative for the future.  Thanks again for you help with this.
0
All Courses

From novice to tech pro — start learning today.