This month's script, GroupedShutdowns, is dedicated to those hard-working systems administrators who've had to manually reboot all their servers in the middle of the night. Manually accessing the console on numerous servers can take time and cause mistakes. Even writing a script that performs the shutdown and restart via your favorite command-line tool can fail if nodes don't respond to the Shutdown command. A properly designed script can come to the rescue by making this repetitive task easier and the results accurate and verifiable.
The GroupedShutdowns script can help you manage a sequenced shutdown and restart of many nodes. You can use any of several available command-line tools to perform remote shutdowns and restarts. However, issuing shutdown/restart commands to your entire server environment simultaneously can cause some obvious problems. I've found that a two-tiered approach works best. Such an approach lets you shut down and restart clustered or load-balanced servers sequentially, so that resources remain online on at least one node throughout the reboot process. This method lets you reboot file or database servers first, then boot Web servers, which are dependent on file-server virtual directories or databases. . . .


Dim oFSO, oTS, sClient, oWindows, oLocator, oConnection, oSys
Dim sUser, sPassword
'set remote credentials
sUser = "Administrator"
sPassword = "bhiad,aat!"
'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(6) '<---remember to change this to 4,5,6, or 12 and remove this message b4 useing.'
Next
Loop
'close the text file
oTS.Close
WScript.Echo "All done!"
scriptgod December 14, 2005 (Article Rating: