Search for Windows Domain Users

by Len Parov.

Share
|
Homepage | Submit your article | Contact | TOS
More articles on microsoft os family  

You are here: Categories » Computers and technology » Microsoft OS family

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:

'***************************************************************
'*** The script searches for a username in one on more domains by
'*** looking for a match on the string of characters you specify.
'***
'*** The syntax:
'*** cscript //nologo FindUser.vbs string dom1[;dom2]
'*** where string is used to match against the username
'*** dom1;dom2 is the semicolon separated list of one or
'*** more domains to search (no limit on number of entries)
 
'***************************************************************
'*** variable declaration
 
Dim sName 'string to match against
Dim sDom 'string storing list of domains
Dim aDom 'array storing list of domains
Dim iCount 'counter variable
Dim oDomain 'object representing domain
Dim oUser 'object representing user account
Dim sLine 'string containing results of the search
 
'***************************************************************
'*** variable initialization
 
sName = Wscript.Arguments(0)
sDom = Wscript.Arguments(1)
aDom = Split(sDom, ";")
 
'***************************************************************
'*** search for matches in the loop
 
For iCount=0 To UBound(aDom)
 
Set oDomain = GetObject("WinNT://" & aDom(iCount))
oDomain.Filter = Array("user")
For Each oUser in oDomain
If InStr(1, oUser.name, sName, 1) > 0 Then
sLine = oDomain.Name & "\" & oUser.Name & ";"
SLine = sLine & oUser.Description & ";"
SLine = sLine & OUser.FullName & ";"
WScript.Echo sLine
End If
Next
 
Next
 

Running the Hack

When you run FindUser.vbs using Cscript.exe in a command-prompt window, you can easily find the full name and domain for a user, given his username. For example, when I search to see if the username bsmith is present in the MTIT domain, I find that user Bob Smith is assigned that username

Leave a comment or ask a question
Total comments: 0

Microsoft OS family Disclaimer

  • The e-articles directory is not responsible for any and all copyright infringements by writers and authors. If you suspect the information contained by this page for any copyright infringements, please contact us to investigate the issue
SharePoint Development is Evolving a Great tool for E~learning - Sharepoint is evolving at a rapid pace in the area of E-learning. Many companies and organizations are installing Microsoft based Sharepoint. They have employed many consultants to get more from t (more...)
Bookmarking websites as favorites - Bookmarking web (more...)
Web slices in Internet Explorer 8 - Another really excellent feature in Windows 7 Internet Explorer 8 is known as Web slices. Web slices keep an eye on distinctive information that is continuously being updated so th (more...)
Internet Explorer 8 Automatically Completes Address - Internet Explorer 8 with Windows 7 helps you surf the Internet quicker. With the latest version of IE you need not open up a new window to find information such as driving directio (more...)
Setting up a shared internet connection in Windows XP - If you have one computer connected to the internet (from now on called the "server"), and another connected to that computer (from now on called the "client") via a wirel (more...)
Find and Replace Registry Keys from a Command Line - Using the Regfind utility, you can easily search the Registry for a value, regardless of the key, and replace it. Regfind (from the Windows 2000 Server Resource Kit) can be an invalua (more...)
How to Execute a Command on Each Computer in a Domain - This handy script lets you easily run any command on a specified subset of computers in your domain. Running the same command on multiple computers in your domain can be tedious indeed, (more...)
Top Five Tools in Windows 2000 - Here's one IT professional's take on five third-party tools for Windows 2000 every system administrator should have. There can be no doubt that with every release of Microsoft's opera (more...)
Designing Active Directory for Exchange Server 2007 - Active Directory (AD) is a necessary and fundamental component of any Exchange 2007 implementation. That said, organizations do not necessarily need to panic about setting up Active Directory in (more...)
Delegate Control of an OU to a User - Rather than use the Delegation of Control Wizard, use this script to delegate authority over an organizational unit (OU) to a particular user. By delegating administrative responsibilit (more...)

 
free content
    Copyright © 2006 - 2012 e-articles.info.
The texts, articles and tutorials in the directory are property of their respective owners and authors.