SideBar    New Tricks for Your Scripting Tool Belt
DOWNLOAD THE CODE:
Download the Code 48416.zip

For those who prefer a third-party shutdown tool, Sysinternals offers PsShutdown (http://www.sysinternals.com/utilities/psshutdown.html), which provides several additional switch options. You can substitute PsShutdown for shutdown.exe in the GroupedShutdowns script. Depending on what tools you have installed on a PC and how they were installed, you could have more than one version of a tool on your testing PC. If you specify a full path to the tool's location (e.g., C:\resourcekit\shutdown.exe), you can avoid mistakenly running a version of shutdown.exe that has a different syntax. However, if you specify only the filename at a command line or in your scripts and use the shutdown.exe version located first in the path, you might find that you're running a different version of the command than you thought. If your PC has more than one version of shutdown.exe, as my PC did, the shutdown.exe command could fail if you specify switch options that the other version doesn't support. If you aren't sure whether your PC has duplicate versions of a tool, use the Windows 2000 Server Resource Kit Where utility (where.exe) to find all the versions. This sample Where command locates the shutdown.exe file in the PATH variable:

where $path:shutdown.exe 

Using GroupedShutdowns
This script assumes that sleep.exe, uptime.exe, and shutdown.exe are in the path on your testing PC. If they aren't in the path, you'll need to specify their location in the script code. To get the GroupedShutdowns script working in your environment, follow these steps:

  1. Download the script from the Windows Scripting Solutions Web site. Go to http://www.windowsitpro.com/windowsscripting, enter 48416 in the InstantDoc ID text box, then click the 48416.zip hotlink.
  2. Configure the reboot-target input-list location. You can include spaces in this pathname. The input file should list one server per line. On each line in the input file, include the group number (1 or 2), a comma, and the server name, as you can see in the sample input file that Figure 1 shows.
  3. Configure the location of the log file that will contain the results of the final uptime test. You can include spaces in this pathname.
  4. Configure the number of seconds for the timeout duration after shutdown and before the Ping test begins. A good starting setting is 240 seconds. The point of using a timeout is to give the server hardware time to actually shut down. Remember that the server doesn't actually shut down until 120 seconds after the Shutdown command is issued. If the timeout is too small, the server might not shut down in time and could still respond to the Ping test, giving you the false impression the server is back online when it's actually still shutting down. The server's Ping response could cause the script to start rebooting the second group of servers before the first group is actually back online. You might need to increase the timeout value if you have applications or services-that take a long time to either allow the server to shut down or to return online.
  5. Customize the shutdown code if you need a different message or arguments or if you need to configure a shutdown reason.

Making Shutdowns More Fun
As you've seen, the GroupedShutdowns script makes the process of shutting down and restarting multiple servers much easier to manage and, as an added benefit, gives you two new techniques for your scripting toolkit. Start using the script, and you'll soon find yourself spending less time on multiple-server shutdowns and getting the job done with greater accuracy.

Dick Lewis (dlewis@windowsitpro.com) is a senior systems engineer with Lewis Technology in Riverside, California. He is an MCSE and an MCT specializing in enterprise management of Windows Server 2003, Windows 2000, and Windows NT servers and workstations.

End of Article

Prev. page     1 [2]     next page -->



You must log on before posting a comment.

If you don't have a username & password, please register now.

Reader Comments

This would work as well;

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

Article Rating 2 out of 5

Great article on automating shutdowns across an enterprise. Thanks

jpetersen78

Article Rating 5 out of 5

 
 

ADS BY GOOGLE