I always feel good when I find a nifty tool that solves some administrative problem. I feel even better when I can script against that tool to automate a task within my environment. IADsTools is such a tool. Found in Windows 2000 Support Tools, IADsTools is a DLL, not a simple command-line utility that you can call. However, it is a COM-based ActiveX automation object that you can invoke from your Windows Script Host (WSH) scripts to perform a variety of actions related to Active Directory (AD), AD replication, and Group Policy. An associated Microsoft Word document in the Win2K Support Tools installation directory describes IADsTools's functions. Let's take a look at a few sample scripts to illustrate the power of some of the more valuable functions that IADsTools provides.
Installing IADsTools
After you install Win2K Support Tools from the \support\tools folder of the Win2K Server CD-ROM, the IADsTools.dll and .doc files will be in the \%programfiles%\support tools directory. To begin using the DLL in your WSH scripts, the DLL must be registered in the registry as a COM object. Open a registry editor and look in HKEY_CLASSES_ROOT for entries beginning with IADsTools. If you find these entries, you're ready to start scripting. If not, you need to register the DLL manually. To do so, start a Windows command shell, navigate to the Win2K Support Tools installation directory, and type
regsvr32 iadstools.dll
After you successfully register the DLL in the system registry , you can begin scripting against it. You can also unregister the DLL, if necessary, by typing
regsvr32 /u iadstools.dll
Before You Get Started
Before you use IADsTools, you should be aware of a few bugs and what steps you can take to work around these problems. The Microsoft articles "Memory Leak with the GetDirectPartnersEx() Function in Iadstools.dll" (http://support.microsoft.com/?kbid=305832) and "Memory Leak Calling the DsGetDcName() or DsGetSiteName() Function" (http://support.microsoft.com/?kbid=300917) describe some memory leaks within IADsTools. The version of Win2K Support Tools that comes with Win2K Service Pack 3 (SP3) corrects these bugs. I strongly recommend that you implement both Win2K SP3 and the Win2K Support Tools update on the servers and clients on which you plan to run IADsTools scripts. You can download Win2K SP3 at http://www.microsoft.com/windows2000/downloads/servicepacks/sp3/default.asp and download the Win2K Support Tools update at http://www.microsoft.com/windows2000/downloads/servicepacks/sp3/supporttools.asp.
Preparing to Use IADsTools
To take advantage of IADsTools's functions, you need to configure your scripts to use the DLL. I used VBScript to prepare all the sample scripts in this article, but you can use any WSH-supported scripting language. To begin, an IADsTools script must include a call to instantiate the scripting object:
Set objIADS=CreateObject
("IADsTools.DCFunctions")
In this case, the COM programmatic identifier (ProgID) IADsTools.DCFunctions creates an object called objIADS that exposes the functions we're interested in. I also suggest enabling verbose logging of the IADsTools calls in IADsTools scriptsthe DLL provides a function called EnableDebugLogging() for this purpose. I typically enable logging in my scripts immediately after I instantiate the IADsTools object by including the following call:
objIADS.EnableDebugLogging(3)