Windows Server Hacks: Search for Domain Users

O'Reilly |  Small Business, Windows Server Add a new comment

Written expressly for system administrators, this
book offers tips and techniques that go beyond the
basic management tasks. The hack shown here will
show you how to programmatically search for a user
in a mixed Windows NT/2000 environment.

Author: Mitch Tulloch
ISBN: 0-596-00647-0

Posted with permission of O'Reilly. Click here
for a detailed description and to learn how
to purchase this title.

Hack #25: Search for Domain Users
Programmatically search for a user in a mixed Windows NT/2000 environment.

If you are in the process of migrating from Windows NT to Windows 2000, you can certainly appreciate the search capabilities provided in Active Directory administrative tools. At the same time, more than ever, you suffer from its absence in the User Manager. This issue becomes especially acute in environments where there is no consistent naming convention or when the naming convention happened to change several times over years. The sorting feature might help, but only provided that a person responsible for creating accounts entered the full name correctly and in the same format. Misspellings or using diminutives and nicknames are other frequent causes of confusion. Your search becomes considerably more time consuming if you manage multiple domains with different naming conventions.

To resolve a problem, you can employ a couple of approaches. The first one involves exporting a user list, along with each user's properties, into a comma-delimited file or a database (e.g., Access or SQL). The main drawback of this solution is the need for regular updates of the exported list. The second drawback, which eliminates the need for maintenance, is using an ADSI-based script.

This approach is shown in the script that follows.

The Code

The script allows searches against multiple domains. In order to accomplish this, you need to provide as the second input argument the list of domains (individual names need to be separated by semicolons). The first argument of the script is the part of the username (of any length) that you want to match against account names. Type the script into Notepad (with Word Wrap disabled) and save it with a .vbs extension as FindUser.vbs:

ITworld LIVE

Small BusinessWhite Papers & Webcasts

White Paper

Small and Medium Business Threat Awareness Report

How aware are small businesses about cyber threats that impact them? Do they consider the right type of defense against hackers? Find out in the Small and Medium Business Threat Awareness Report.

White Paper

Microsoft Volume Licensing Comparison - Small/Med. Business

This quick-reference document lets small and medium organizations (i.e. those with five or more devices) to easily compare the available Microsoft Volume Licensing programs to create a simple, cost-effective and flexible way to benefit from volume licensing.

White Paper

ESG: Oracle Database Appliance: A Simple, Economical Option for SMBs and Independent Software Vendors

Read this technology overview of a DBMS built for SMBs that provides a rapidly-deployable, highly-available platform at an affordable cost

See more White Papers | Webcasts

Ask a question

Ask a Question