Search For a user in all domains?

Posted on 2009-04-27
Last Modified: 2012-05-06
Hello all,
i need to search for a specified user in all trusted domains the tree that we have in our LAN is like this and we have others domains under this root domain which for example,, and so on. ii want to search for a user by using LDAP path, the error that i face i cannot search for a user in root, so is there a way to search like this or only thru the sub domain that the user belong to.

Question by:baghlaf
    1 Comment
    LVL 70

    Accepted Solution


    If they're part of the same forest you can search the global catalog and the domain root as the search base. Example below.

    Dim ldapFilter As String = "(sAMAccountName=TheUserName)"
    Dim adForestRoot As DirectoryEntry("GC://DC=RootDomain,DC=com")
    Dim adSearcher As DirectorySearcher(adForestRoot, ldapFilter)
    Dim adSearchResult As SearchResult = adSearcher.FindOne()

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    [b]Ok so now I will show you how to add a user name to the description at login. [/b] First connect to your DC (Domain Controller / Active Directory Server) SET PERMISSIONS FOR SCRIPT TO UPDATE COMPUTER DESCRIPTION TO USERNAME 1. Open Active …
    Introduction You may have a need to setup a group of users to allow local administrative access on workstations.  In a domain environment this can easily be achieved with Restricted Groups and Group Policies. This article will demonstrate how to…
    This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
    This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now