Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


March 2004

Check Service Status on Local or Remote Servers

Building the script one piece at a time
RSS
Subscribe to Windows IT Pro | See More Task Automation Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

Before you can work with the string of names that make up the sComputerName variable, you must put the names into an array. In their simplest and most common form, arrays are one-column tables of data, the rows of which are identified by index numbers from 0 through the final row number—the upper bound of the array. You can create an array and populate it manually, or you can create an array and populate it from a chunk of existing data. To make the array from existing data, use the Split function to divide the sComputerName variable's content into chunks, using the carriage return/line feed (vbCrLf) as the delimiter. The code that converts the contents of sComputerName into the aComputers array looks like this:

aComputers = Split(sComputerName, vbCrLf)

Now that you have the array, you can use a For Each...Next statement on its contents to print each computer's name and display its services and their status.

Reading Computer Names from AD
To perform a complete inventory of the services running on all servers in AD (or a portion of AD), you can read the names directly from the domain controller (DC) instead of manually inputting the names or reading them from a text file. Connecting to the servers this way ensures that you inventory only present servers—and avoids the potential problem of misspelling server names—but results in a lot of output.

Obtaining the list of servers is easy: Connect to the Lightweight Directory Access Protocol (LDAP) service on the DC, retrieve the names of all computers in AD (or a portion of AD), and place those names into a collection. Next, run a For Each...Next statement against the collection to get each computer's common name (CN), then plug in that information to get the service status on each computer. For example, to query the contents of the Computers container, you'd use the code that Listing 5 shows. The rest of the For Each...Next statement enumerates the services on each computer and their status.

Output Redirection
Web Listing 1 (http:www.winnetmag.com, InstantDoc ID 41670) shows the assembled script, GetServiceStatus.vbs. Because this script can produce a lot of output, if you plan to run the script against more than one or two servers, I recommend that you don't try to read the output from the command window. Instead, redirect the output to a file, as follows:

getservicestatus.vbs [arguments] 
> status.txt

Not only can you now check service status on local or remote computers, but you can also provide Help for your scripts, format script output, and work from a variety of input types. You'll probably find these abilities useful in other kinds of reporting scripts.

End of Article

   Previous  1  2  [3]  Next  


Reader Comments
Very useful. Is there any way of setting script attributes ? (such as account credentials ?)

Andrew Whitton May 14, 2004


You can specify the credentials fairly easily; see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/setting_the_default_process_security_level_using_vbscript.asp for details.

paulrobichaux December 04, 2004 (Article Rating: )


You must log on before posting a comment.

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




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

New Microsoft/Yahoo! Deal? No

On Sunday, the Times of London reported that Microsoft had renewed talks with failing Internet giant Yahoo! and would manage its search engine for 10 years, while Yahoo! would retain control of its email, messaging, and content services. This report ...

How can I stop and start services from the command line?

...


Task Automation Whitepapers Essential Guide to E-discovery and Recovery for Microsoft Exchange

Continuous Data Protection and Recovery for Microsoft Exchange

Protecting (You and) Your Data with Exchange Server 2007

Related Events Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing