We help IT Professionals succeed at work.
Get Started

VB .Net AD membership lookup

Last Modified: 2012-05-10
Hey guys

i have been working on this code that gets the memberships for a user and it works but it gives me the full path to the group, is there any way i can make it only give me the common name? i

so it i want it to look like this, btw is this put into a rich textbox, below if the piece of code i am working with
Dim child As New System.DirectoryServices.DirectoryEntry("LDAP://DC=abc,DC=local")
        Dim searcher As New DirectorySearcher(child)
        Dim result As SearchResult

        searcher.SearchRoot = child
        searcher.Filter = "(&(objectClass=user)(objectCategory=person)(sAMAccountName=" & tcopyfrom.Text & "))"
        result = searcher.FindOne

        '   tmembership.Text = result.GetDirectoryEntry().Properties("cn").Value() & vbCrLf
        For Each member As String In result.GetDirectoryEntry().Properties("memberOf").Value()

            tmembership.Text = tmembership.Text & member & vbCrLf

Open in new window

Watch Question
Top Expert 2010
This problem has been solved!
Unlock 2 Answers and 4 Comments.
See Answers
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
Ask ANY Question

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

  • Troubleshooting
  • Research
  • Professional Opinions
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