User1877682370 posted
I would like to get at the user logins for all the members of a pre-selected AD group so that i can display this information on an admin page in my application (all my permissions are held in sitemap and role membership is done in AD).
I cant seem to get this working, although i can easily get the surname and firstname of all the users in the passed in group:
Public Function getUsersInRole(ByVal roleName As String)
Dim usersList As New StringBuilder()
Try
Dim search As DirectorySearcher = New DirectorySearcher()
search.Filter = String.Format("(cn={0})", roleName.ToString())
search.PropertiesToLoad.Add("member")
search.PropertiesToLoad.Add("name")
Dim results As SearchResultCollection = search.FindAll()
Dim result As SearchResult
If (results.Count > 0) Then
For Each result In results
For Each member As String In result.Properties("member")
usersList.Append(member & "/")
Next
Next
End If
Return usersList.ToString()
Catch ex As Exception
Throw ex
Return String.Empty
End Try
End Function
this returns something like:
CN=smith John,OU=Users,OU=HQ,DC=landmarc,DC=local/CN=smith john,OU=Users,OU=HQ,DC=landmarc,DC=local/
but as you can see there is a problem getting at any user specific info if i get 2 john smiths back in the same group. If i could get the logins (which are unique) i could get at the title, email, phone number (etc) attributes from AD.
Can anyone help me with altering my code so I can get back the logins, or at least point me in the right direction. I do have an ADSI linked server set up on my sqlserver db so i could do this through SQL but again can't seem to find the correct syntax for
this.
If anyone knows how to achieve what i want through either method i'd be grateful to hear from them!
cheers,