I need to add a parameter to a directorysearcher.filter rather than using
hard-coded text. I have the following code that finds all members of an AD
group and then for each of those results tries to find that users
samAccountName.
Perhaps I'm going about this incorrectly but I know if I could pass my
searcher.filter a paramter rather than typing "cn=jason", etc this code
would work, any help would be very much appreciated!:
'Get all users in the G_SCA_Change_Control_Approvers group
Dim Approvers_entry As New
DirectoryEntry("LDAP://CN=G_SCA_Change_Control_Approvers,OU=Groups,DC=sca ,DC
=hin,DC=sk,DC=ca")
Dim Approvers_result As String
Dim entry As New DirectoryEntry("LDAP://SCA")
Dim searcher As New DirectorySearcher(entry)
Dim result As SearchResult
Dim results As SearchResultCollection
searcher.PropertiesToLoad.Add("samAccountName")
For Each Approvers_result In Approvers_entry.Properties("member")
Approvers_result = Approvers_result.ToString.Split(",")(0)
Approvers_result = Approvers_result.ToString.Split("=")(1)
txtADUserGroup.Text = txtADUserGroup.Text & Approvers_result & vbNewLine
searcher.Filter = String.Format("(&(objectClass=person)(cn=<Approver s-result
needs to go here rather than having to type the cn of the user>))")
result = searcher.FindOne
txtADUserGroup.Text = txtADUserGroup.Text &
result.Properties("samAccountName")(0).ToString() & vbNewLine
Next
Thanks in advance,
Jason