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?
Printable View
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?
Bumping this because it is pretty important for me to continue my project...
Searching MSDN came up with this , haven't tried it, though.
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.
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:
'syntax ListBox1.Items.AddRange(GetMembersOfGroup("edneeis.local", "Administrators")) Private Function GetMembersOfGroup(ByVal domain As String, ByVal group As String) As String() 'set domain path Dim de As New DirectoryEntry(String.Format("LDAP://{0}", domain)) Dim srch As New DirectorySearcher(de) 'filter find all groups with the name provided srch.Filter = String.Format("(&(objectClass=group)(Name={0}))", group) Dim al As New ArrayList For Each res As SearchResult In srch.FindAll 'get all members For Each obj As Object In res.Properties("Member") 'trim to a more legible name al.Add(TrimToName(obj)) Next Next Return CType(al.ToArray(GetType(String)), String()) End Function Private Function TrimToName(ByVal path As String) As String Dim parts() As String = path.Split(",") Return parts(0).Replace("CN=", String.Empty) End Function
Thanks, I am not on a network until next week now, so I will have to give it a try then.
Appreciate it.
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?Quote:
Originally Posted by dani2