Link to home
Start Free TrialLog in
Avatar of Tom Powers
Tom Powers

asked on

how do I in VB.NET Grab Groups with an OU and display them in a liewview control

I in VB.NET Grab AD Groups within an OU  and display them in a liewview control. the Code is

 Private Sub FillDropdown()
        Dim oroot As DirectoryEntry = New DirectoryEntry("LDAP://OU=Groups Application,OU=Unified Data Centers,DC=one,DC=ads,DC=che,DC=org")
        Dim osearcher As DirectorySearcher = New DirectorySearcher(oroot)
        Dim oresult As SearchResultCollection
        Dim result As SearchResult
        Dim list As New List(Of String)

        osearcher.Filter = "(&(objectCategory=user)(memberOf=OU=Groups Application,OU=Unified Data Centers,DC=one,DC=ads,DC=che,DC=org))"
        ' search filter; only display emp with firstname / lastname pair
        osearcher.PropertiesToLoad.Add("name") ' member
        oresult = osearcher.FindAll()


        For Each result In oresult
            If Not result.GetDirectoryEntry.Properties("name").Value Is Nothing Then
                List.Add(result.GetDirectoryEntry.Properties("name").Value.ToString())
                Call List.Sort()
            End If
        Next
        ' LVGlobal.subitems.add


        ListBox1.Items.Add(list)
    End Sub

Open in new window

Avatar of Kevin Stanush
Kevin Stanush
Flag of United States of America image

I'm not clear what the question and/or problem is.
Avatar of Tom Powers
Tom Powers

ASKER

i'M TRYING TO RETRIEVE ALL THE Active Directory Groups in this OU OU=Groups Application,OU=Unified Data Centers,DC=one,DC=ads,DC=che,DC=org
Just the names of AD Groups is what I'm trying to retrieve and populate a Listview control there is something with above code that is wrong. Please Help. Thanks
I don't code in VB, but your LDAP directory search filter needs to be "(objectcategory=group)", right now it contains a 'memberof' clause that does not belong there.  Use "objectcategory=*" to see everything for testing.
Hey so I changed the code to pull up all groups in an OU HERE IT IS
 Private Sub FillDropdown()
        Dim oroot As DirectoryEntry = New DirectoryEntry("LDAP://OU=Groups Application,OU=Unified Data Centers,DC=one,DC=ads,DC=che,DC=org")
        Dim osearcher As DirectorySearcher = New DirectorySearcher(oroot)
        Dim oresult As SearchResultCollection
        Dim result As SearchResult
        Dim list As New List(Of String)

        osearcher.Filter = "(objectCategory=group)"
        ' search filter; only display emp with firstname / lastname pair
        osearcher.PropertiesToLoad.Add("memberof") ' member
        oresult = osearcher.FindAll()


        For Each result In oresult
            If Not result.GetDirectoryEntry.Properties("group").Value Is Nothing Then
                list.Add(result.GetDirectoryEntry.Properties("member").Value.ToString())
                Call list.Sort()

            End If
        Next
        ' LVGlobal.subitems.add


        ListBox1.Items.Add(list)

    End Sub

Open in new window

i GET THIS MESSAGE WHENTRYING TO GRABS ALL AD gROUPS INTHIS OU
User generated imageI also have a function that tries to grab all the groups for a given member
here is code
User generated imagecollection.png
ASKER CERTIFIED SOLUTION
Avatar of Kevin Stanush
Kevin Stanush
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Never heard anything back, so don't know the outcome of the last reply