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


November 13, 2006

Quickly Finding User Accounts Anywhere in an Active Directory Forest


RSS
View this exclusive article with VIP access -- click here to join |
See More Active Directory (AD) Articles Here | Reprints | Or sign up for our VIP Monthly Pass!
Main Article    Rem

I work in a network that contains a single forest made up of many Active Directory (AD) domains. I need to verify that a user account exists and in what domain it exists. I know I can use Active Directory Users and Computers to find an account. How can I script this task instead?
You can accomplish this task by writing a script that queries a global catalog server in your forest. Because each global catalog server in a forest contains a partial replica of all objects in all domains within the forest, it's the best place for locating AD objects such as user accounts. Listing 1, shows how you can use the ADSI OLE DB provider to search a global catalog server in a forest for a user account whose common name (cn attribute) begins with the letters eth. To make this script a bit more dynamic, I bind to the rootDSE object.

The rootDSE object contains the base Directory System Agent (DSA) information from any domain controller in the domain. DSA information includes data such as the current DNS host name and the various naming contexts in an AD implementation, such as the default schema, and configuration naming contexts. The code at callout A in Listing 1 demonstrates how to bind to the rootDSE, retrieve values from this object (in this case, the script retrieves the distinguished name of the forest, which is stored in the rootDomainNamingContext), and create a variable containing an AdsPath that uses the GC moniker. The GC moniker instructs the script to connect to any domain controller serving as a global catalog server. Under the covers, the GC moniker makes a connection request by using port 3268, which is the listening port for all AD global catalog servers. The actual bind operation performs authentication to an available global catalog server by using the credentials of the currently logged-on user. . . .


Already a VIP member?
Please log on to view the full article

Why become a VIP member?

VIP-only online access
VIP CD delivered twice a year: offline access to the entire Windows IT Pro article library
Monthly issue of your choice of Windows IT Pro or SQL Server Magazine

Subscribe Now
Reader Comments
I receive an invalid entry reference message at Line 27 Char 28.

Commandline used:
finduser.wsf /attrib:displayName=cr*

nitz@pabgames.net November 28, 2006 (Article Rating: )


Try running the command by appending cscript in front of finduser.wsf: cscript finduser.wsf /attrib:displayName=cr*
Also, are you sure you're running Windows Script Host 5.6?

EthanW December 19, 2006 (Article Rating: )


I do not see the .zip file link at the beginning of the article do download the code as you recommend. I am a subscriber, could you please send me the link? Listing 1 as is always returns "No users found with that name" but I know that in my forest they exist (I do edit commonNamePart). Thank you, it would be great if I can get it to work.

ppierani December 19, 2006 (Article Rating: )


It would be more useful if I could find the link to download the code.

sogadmin January 30, 2007 (Article Rating: )


It's interesting that it is "recommended" to download the script yet there is no link for the sourcecode to be found. <sigh>

gwojan February 08, 2007 (Article Rating: )


To download the zip file containing the script, click the Download the Code button at the beginning of the article (top left, under the title info). The direct link is <a href="http://www.windowsitpro.com/Files/07/94027/94027.zip">here</a>.
Anne Grubb, senior editor, Windows IT Pro

AnneG_editor May 09, 2007 (Article Rating: )


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...


Related Articles Copy Group Memberships from One AD User to Another

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

Meeting Compliance Objectives in SharePoint

Email Controls and Regulatory Compliance

Related Events Troubleshooting Active Directory

Cutting Costs with Client Management

7 Ways To Get More From Your SharePoint Deployment Now

Check out our list of Free Email Newsletters!

Active Directory (AD) eBooks The Essentials Series: Active Directory 2008 Operations

Keeping Your Business Safe from Attack: Monitoring and Managing Your Network Security

Windows 2003: Active Directory Administration Essentials

Related Active Directory (AD) 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.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement