We help IT Professionals succeed at work.

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

435 Views
Last Modified: 2017-04-11
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

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.

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:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Kevin StanushApplication Developer

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

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions