What I need to do is to get a list of all users from an AD OU and display them in a dropdown. But what I need is both First name and Last name to show in the dropdown.
what I have is this and it works, but I don't need sammacocountname
Dim
allUsers AsNewArrayList()
Dim
searchRoot AsNewDirectoryEntry("LDAP://_)
Dim
search AsNewDirectorySearcher(searchRoot)
search.SearchScope =
SearchScope.Subtree
search.Filter =
"(&(objectClass=user)(objectCategory=person))"
'search.FindAll();
search.PropertiesToLoad.Add(
"samaccountname")
search.PropertiesToLoad.Add(
"givenname")
search.PropertiesToLoad.Add(
"sn")
Dim
result AsSearchResult
Dim
resultCol AsSearchResultCollection
= search.FindAll()
If
resultCol IsNotNothingThen
For
counter AsInteger
= 0 To
resultCol.Count - 1
result = resultCol(counter)
If
result.Properties.Contains("samaccountname")
Then
kouts1
Member
52 Points
43 Posts
Get users (first and Last name) from AD OU and display in dropdownlist
Feb 16, 2012 03:49 PM|LINK
Hi all,
What I need to do is to get a list of all users from an AD OU and display them in a dropdown. But what I need is both First name and Last name to show in the dropdown.
what I have is this and it works, but I don't need sammacocountname
Dim allUsers As New ArrayList()
Dim searchRoot As New DirectoryEntry("LDAP://_)
Dim search As New DirectorySearcher(searchRoot)
search.SearchScope =
SearchScope.Subtree
search.Filter =
"(&(objectClass=user)(objectCategory=person))"
'search.FindAll();
search.PropertiesToLoad.Add(
"samaccountname")
search.PropertiesToLoad.Add(
"givenname")
search.PropertiesToLoad.Add(
"sn")
Dim result As SearchResult
Dim resultCol As SearchResultCollection = search.FindAll()
If resultCol IsNot Nothing Then
For counter As Integer = 0 To resultCol.Count - 1
result = resultCol(counter)
If result.Properties.Contains("samaccountname") Then
d1.Items.Add(
DirectCast(result.Properties("samaccountname")(0), [String]))
End If
Next
End If
thanks!
kouts1
Member
52 Points
43 Posts
Re: Get users (first and Last name) from AD OU and display in dropdownlist
Feb 16, 2012 03:53 PM|LINK
Nevermind I got it! If anyone needs:
Dim allUsers As New ArrayList()
Dim searchRoot As New DirectoryEntry("LDAP://")
Dim search As New DirectorySearcher(searchRoot)
search.SearchScope =
SearchScope.Subtree
search.Filter =
"(&(objectClass=user)(objectCategory=person))"
search.PropertiesToLoad.Add(
"name")
search.PropertiesToLoad.Add(
"givenname")
search.PropertiesToLoad.Add(
"sn")
Dim result As SearchResult
Dim resultCol As SearchResultCollection = search.FindAll()
If resultCol IsNot Nothing Then
For counter As Integer = 0 To resultCol.Count - 1
result = resultCol(counter)
If result.Properties.Contains("givenName") And result.Properties.Contains("sn") Then
d1.Items.Add(
DirectCast(result.Properties("givenName")(0), [String]) + " " + (DirectCast(result.Properties("sn")(0), [String])))
End If
Next
End If
SonicMan
Participant
1472 Points
228 Posts
Re: Get users (first and Last name) from AD OU and display in dropdownlist
Feb 20, 2012 04:29 AM|LINK
Hi
Thanks for your solution.