Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


June 12, 2006

Using VBScript to List Member Servers' Scheduled Tasks

RSS
Subscribe to Windows IT Pro | See More Scripting Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!
Main Article    Rem, July 2006

Download the Code Here

I want a list of scheduled tasks for the member servers in my Active Directory (AD) domain. The list should include the user accounts the servers use to run the tasks. I also want to be able to import the list into Microsoft Excel. How can I do this?

I'll answer this question in two parts. First, I explain how to get an appropriate list of computers by searching AD. Second, I show you how to get the scheduled tasks from each computer in the list. Microsoft provides an excellent overview of how to search AD in the "Microsoft Windows 2000 Scripting Guide" (http://www.microsoft.com/technet/scriptcenter/guide). Briefly, using a script to search AD requires the following steps:

  1. Create a Connection object (ADODB.Connection) and use its Open method to establish a connection to AD.
  2. Create a Command object (ADODB.Command) and set its ActiveConnection property to the open Connection object.
  3. Set the Command object's CommandText property to an appropriate LDAP query string.
  4. Use the Command object's Execute method to return a RecordSet object.
  5. Close the Connection object.

The ListComputers.vbs script in Listing 1 uses VBScript to list all Computer objects in the current domain. The code at callout A in Listing 1 uses the rootDSE object to retrieve the current domain's name, and the LDAP query at callout B selects the common name (CN) property (i.e., just the computer name) for all Computer objects. The code at callout C iterates the RecordSet and echoes the Value property of the CN field for each record. The CN field (or column) exists because that's the property that the LDAP query at callout B specifies.

Getting a list of domain controllers (DCs) requires a different approach. Listing 2's script, ListDCs.vbs, shows how to use VBScript to get the list. The code at callout A in Listing 2 uses the rootDSE object to return the current domain's configuration naming context, and the LDAP query at callout B selects the AdsPath property for all nTDSDSA objects. In the AD hierarchy, the nTDSDSA object's parent is a DC. The code at callout C iterate the RecordSet, retrieves the Parent object of each nTDSDSA object, and echoes the Parent object's CN property (i.e., the DC's name).

Because AD doesn't have attributes that store a computer's role (e.g., workstation, member server, DC), you can't include such attributes in a query. To work around this limitation, you can include the operatingSystem attribute in the LDAP query. If the operatingSystem attribute contains the word "server," then the computer is a server. However, note that DCs will be included in such a search.

A script can generate a member server list that doesn't include DCs by first retrieving a list of DCs. After it gets the list of DCs, the script can retrieve a list of Computer objects. If a Computer object's operatingSystem attribute contains the word "server" and the Computer object's name isn't in the list of DCs, the computer is a member server. I've written a complete script, EnumComputers.js, that performs this task for you. It's too long to print here, but you can download it from the Windows Scripting Solutions Web site at http://www.windowsitpro.com/windowsscripting, Instant-Doc ID 50325.

The EnumComputers.js script has the following command-line syntax:

[cscript] EnumComputers.js /wks 
| /dc | /srv [/dc]
EnumComputers.js is intended to run in a command window, so it requires the CScript host. The cscript keyword at the beginning of the command line is required only if CScript isn't your default host. To set CScript as your default host, type into a command window the following command:
 cscript //h:cscript //nologo //s 
   Previous  [1]  2  Next 


Top Viewed ArticlesView all articles
Confirmed: Battery Life Issues Not Windows 7's Fault

Microsoft on Monday issued a lengthy statement about the recent Windows 7 battery controversy, echoing my assessment from earlier in the day, but backing it up with hard, cold evidence. ...

Battery Life Issues Almost Certainly Not Windows 7's Fault

While Microsoft is still investigating a notebook battery life issue that was supposedly caused by Windows 7, some interesting trends have emerged. ...

Microsoft Warns of Windows Version Expirations

Microsoft warned that this year will see three out-of-date Windows versions slip into retirement. ...


Scripting Whitepapers Three Ways to Prevent Insider Risk within Your SCCM-Managed Environment

From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


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 DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2010 Penton Media, Inc. Terms of Use | Privacy Statement