Results 1 to 8 of 8

Thread: Active Directory...How to get users in a group?

  1. #1

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

    Active Directory...How to get users in a group?

    I need to get all the login names and corrisponding friendly names from active directory that are in a certain group. How would I do this?

  2. #2

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Bumping this because it is pretty important for me to continue my project...

  3. #3
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Searching MSDN came up with this , haven't tried it, though.

  4. #4

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Yea, I have tried all the examples I could find. I can get a complete listing of AD users, but I can't get them from a single group right now.

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Here you go, I had to convert it from some code I previously did that got all groups a user was in. I see what you mean about not finding much info on how to reverse that and get all users in a group but this should work:
    VB Code:
    1. 'syntax
    2. ListBox1.Items.AddRange(GetMembersOfGroup("edneeis.local", "Administrators"))
    3.  
    4.     Private Function GetMembersOfGroup(ByVal domain As String, ByVal group As String) As String()
    5.         'set domain path
    6.         Dim de As New DirectoryEntry(String.Format("LDAP://{0}", domain))
    7.         Dim srch As New DirectorySearcher(de)
    8.         'filter find all groups with the name provided
    9.         srch.Filter = String.Format("(&(objectClass=group)(Name={0}))", group)
    10.         Dim al As New ArrayList
    11.         For Each res As SearchResult In srch.FindAll
    12.             'get all members
    13.             For Each obj As Object In res.Properties("Member")
    14.                 'trim to a more legible name
    15.                 al.Add(TrimToName(obj))
    16.             Next
    17.         Next
    18.         Return CType(al.ToArray(GetType(String)), String())
    19.     End Function
    20.  
    21.     Private Function TrimToName(ByVal path As String) As String
    22.         Dim parts() As String = path.Split(",")
    23.         Return parts(0).Replace("CN=", String.Empty)
    24.     End Function

  6. #6

    Thread Starter
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Thanks, I am not on a network until next week now, so I will have to give it a try then.

    Appreciate it.

  7. #7
    Addicted Member dani2's Avatar
    Join Date
    Feb 2005
    Location
    Sibiu.ro
    Posts
    191

    Re: Active Directory...How to get users in a group?

    Hey, that code is not working. You should come back and make it work

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Active Directory...How to get users in a group?

    Quote Originally Posted by dani2
    Hey, that code is not working. You should come back and make it work
    You may want to be more specific then that. It works when I run it. What makes you say otherwise?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width