Chris addresses a batch of common questions from readers on ready-to-use scripts, useful books, collecting hardware information by script—and yes, ADSI.

Off the Script: Your Questions

Chris addresses a batch of common questions from readers on ready-to-use scripts, useful books, collecting hardware information by script—and yes, ADSI.

Although I promised last month that I’d be starting a series on ADSI this month, I’m going to take a one-month detour. Having recently hosted a chat on www.mcpmag.com, I’m using this month’s column to expand on my answers to the top questions. There’s a good chance many of you have the same questions. And, later in this article, I have managed to include an ADSI question that just happened to be submitted during the chat.

Rodney: Is there one reference that you would recommend to the budding scripter?

There are several books I recommend for Windows Script Host and VBScript:

  • Windows Script Host by Tim Hill (New Riders Publishing, ISBN 1-57870-139-2).
  • VBScript Programmer’s Reference by Adrian Kingsley-Hughes et al (Wrox Press, ISBN 1-86100-271-8).
  • Windows NT/2000 ADSI Scripting for System Administration by Thomas Eck (although this one tends to focus mostly on VB rather than VBScript, probably not the best bet for a newcomer. Published by MTP, ISBN 1-57870-219-4).

Ideally, the best way to learn is by writing scripts. Start with a simple “Hello World” script and go from there. If you have access to an MSDN subscription, you can find wealth of information there. If not, http://msdn.microsoft.com/
scripting
has lots of free resources.

Knoxman: Where can I get pre-written scripts to automate such tasks as creating batches of users?

The MSDN scripting site I just mentioned has lots of sample scripts. Most books include either a CD or a Web site reference that contains the samples used. The Windows 2000 Professional Resource Kit CD contains a good assortment of scripts (and not all of them are ADSI, either!). If you happen to buy a third-party component, it will generally come with samples, too.

But here’s the sleeper hit of the summer: ASP code! You can’t throw a rock in the Barnes and Noble computer section without hitting a book that has some ASP code in it. Go through the ASP pages and copy the part between "<%" and "%> or between "". You’ll find that with a little tweaking, you’ll have a script that runs fine in the WSH.

Alnico: How would you go about writing a script to collect system information (hard drive, RAM, BIOS version, etc)?

Well, there are third-party components that can be used in a script to query configuration information, but you can also do it with the WSHShell component. You can use this built-in Windows component to query registry information, including Hardware, TCP/IP configuration, BIOS information, and the like. The registry contains everything you need to know about your system. Once you know where the information is stored in the registry, here’s how you query it from your script:

' Regquery.vbs
' Query current IP address and BIOS revision date
Dim objShell, strIP, strBIOS
Set objShell=CreateObject("WScript.Shell") strIP=objShell.RegRead("HKEY_LOCAL_MACHINE\System\
     CurrentControlSet\ Services\{GUID}\
     Parameters\Tcpip\IPAddress") strBIOS=objShell.RegRead("HKEY_LOCAL_MACHINE\
     System\CurrentControlSet\Control\Biosinfo\
     SystemBiosDate")

The registry is the best location for any information about your system, or you can query the Active Directory.

Lanre:What’s ADSI scripting?

ADSI scripting is any scripting that uses the Active Directory Services Interface to view or change information stored in the Active Directory. You can, though, use the ADSI to access and change NT information even if Active Directory is not installed. One of the namespaces (interface to services) exposed through ADSI is WinNT. You can use this namespace to view and change information on a Windows NT domain. The following script lists all Active Directory namespaces currently installed:

' ADView.vbs
Dim objServices, strList, strProvider
set objServices=GetObject("ADs:")
For Each strProvider in objServices
     strList=strList & strProvider.name & vbcrlf
Next
WScript.Echo strList

As you can see in Figure 1, I currently have WinNT, NWCOMPAT, NDS, and LDAP installed on my machine.

Figure 1. Installed namespaces.

The two other namespaces that ship with Windows 2000 are IIS and DSMigrate. If you are dealing with Microsoft technologies alone, you need only concern yourself with WinNT, IIS, and LDAP. As I mentioned, the WinNT namespace allows you to access NT information. IIS allows you to connect to—you guessed it: IIS. The LDAP namespace allows access to Active Directory information.

We can modify one line in the previous script to list every available NT domain. Replace the third line of the script with:

Set objServices=GetObject("WinNT:")

To extend that even further. change the same line to...

Set objServices=GetObject("WinNT://Domain")

...we will receive a listing of every resource in the domain: Users, groups, and so on. As promised, my series on ADSI scripting will start next month. Until then, happy scripting!

About the Author

Chris Brooke, MCSE, is a contributing editor for Redmond magazine and director of enterprise technology for ComponentSource. He specializes in development, integration services and network/Internet administration. Send questions or your favorite scripts to [email protected].

comments powered by Disqus
Most   Popular