Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  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. . . .

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 log on before posting a comment.

If you don't have a username & password, please 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. ...

New Microsoft/Yahoo! Deal? No

On Sunday, the Times of London reported that Microsoft had renewed talks with failing Internet giant Yahoo! and would manage its search engine for 10 years, while Yahoo! would retain control of its email, messaging, and content services. This report ...

How can I stop and start services from the command line?

...


Related Articles Copy Group Memberships from One AD User to Another

Active Directory (AD) Whitepapers Sustainable Compliance: How to reconnect compliance, security and business goals

Managing Unix/Linux with Microsoft System Center Operations Manager 2007 Cross Platform Extensions Beta

Addressing the Insider Threat with NetIQ Security and Administration Solutions

Related Events Concrete Ways to Make Sure Your SharePoint Deployment Doesn't Blow Up

Introduction to Identity Lifecycle Manager "2"

Power Up! With Virtualization Online Conference

Check out our list of Free Email Newsletters!

Active Directory (AD) eBooks Keeping Your Business Safe from Attack: Monitoring and Managing Your Network Security

Keeping Your Business Safe from Attack: Encryption and Certificate Services

Windows 2003: Active Directory Administration Essentials

Related Active Directory (AD) Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


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 Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing