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

Visual Basic.NETActive Directory.NET Programming

Avatar of undefined
Last Comment
Kevin Stanush

8/22/2022 - Mon
Kevin Stanush

I'm not clear what the question and/or problem is.
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
Kevin Stanush

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.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Tom Powers

ASKER
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
collection.pngI also have a function that tries to grab all the groups for a given member
here is code
Exception.pngcollection.png
ASKER CERTIFIED SOLUTION
Kevin Stanush

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Kevin Stanush

Never heard anything back, so don't know the outcome of the last reply