Results 1 to 2 of 2

Thread: Problem sorting/grouping on objectclass property of AD search results

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2006
    Posts
    746

    Problem sorting/grouping on objectclass property of AD search results

    Hello again,

    I *have* searched for answer on this but couldn't find anything so apologies if I'm covering old ground.

    I have the following code to enumerate all objects in an OU

    Public Sub GetOus(ByVal strDomainName As String)
    Dim deEntry2 As New DirectoryEntry("LDAP://" & strDomainName.ToString())

    Dim DSearch As New DirectorySearcher(deEntry2)
    With DSearch
    .SearchScope = SearchScope.OneLevel
    .PropertiesToLoad.Add("name")
    .PropertiesToLoad.Add("objectclass")
    .PropertiesToLoad.Add("DistinguishedName")
    .Sort.PropertyName = "name"
    '.Filter = "objectclass=organizationalUnit"
    '.Sort.Direction = SortDirection.Descending
    End With

    End Sub

    Now, it works fine but there are, obviously, some OUs that contain sub-OUs as well as computer/user objects. I would like to be able to sort the results so that the objects that are OUs are at the top and any that are computers/users are after it. I'm sure I can do it using the objectclass parameter but I'm struggling to figure out the exact syntax.

  2. #2
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: Problem sorting/grouping on objectclass property of AD search results

    If my memory serves me correctly, you have to query each one separately. There is no built-in functionality to do this.

    If you are wanting to load all OUs and the sub-objects of all of those OUs, then you are going to create a function to load a single OU and then call that recursively.

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