Results 1 to 2 of 2

Thread: [2005] Active Directory - Get all OU's undernath an OU

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2000
    Location
    NJ, USA
    Posts
    326

    [2005] Active Directory - Get all OU's undernath an OU

    I am trying to search for all users under an OU. However, one OU may contain other OU's underneath of it.

    For instance, the tree structure would look kind of like:

    Country
    -USA
    --NJ
    ---City
    --NY

    Since, the structure could change at any time I don't know how many sub OU's I have at any one time. However, the users I'm searching for are always within the last OU. Basically, what I need to do is iterate through each OU looking for more OU's underneath it and work my way down. This is what I have so far.

    VB Code:
    1. Dim entry As New DirectoryServices.DirectoryEntry("LDAP://max.com/OU=USA,DC=Country,DC=com")
    2.         Dim searcher As New System.DirectoryServices.DirectorySearcher(entry)
    3.         Dim result As System.DirectoryServices.SearchResult
    4.  
    5. searcher.Filter = "(&(objectCategory=user))"
    6.         searcher.PropertiesToLoad.Add("name")
    7.         searcher.PropertiesToLoad.Add("distinguishedName")

    I think I need to modify the searcher.Filter line but I may be way off.
    Last edited by Chris H; May 2nd, 2006 at 10:26 AM.
    VB.NET 2005 Express with .Net 2.0
    C# 2010 .Net 4.0

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2000
    Location
    NJ, USA
    Posts
    326

    Resolved [RESOLVED] [2005] Active Directory - Get all OU's undernath an OU

    It never fails, as soon as I post a question I find the answer. The filter should be, searcher.Filter = "(&(objectCategory=organizationalUnit))"

    I used the Active Directory MMC to find it.
    VB.NET 2005 Express with .Net 2.0
    C# 2010 .Net 4.0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width