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

Tom Powers
Tom Powers used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Kevin StanushApplication Developer

Commented:
I'm not clear what the question and/or problem is.

Author

Commented:
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 StanushApplication Developer

Commented:
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.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
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
Application Developer
Commented:
If your intent is to get the names of the groups in the OU, I don't know why you are referencing 'memberof' and 'member' as those attributes have nothing to do with the name of the group.  You should simplify the code loop to show the names by just showing the name of the group, ie:

list.Add(result.GetDirectoryEntry.Name)

Here is essentially the same thing you are trying to do (assuming I understand what you want to do):

https://www.experts-exchange.com/questions/27661709/vb-net-list-active-directory-groups.html
Kevin StanushApplication Developer

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial