469,579 Members | 1,161 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Parameter in a directorysearcher.filter?

Jay
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
Nov 18 '05 #1
1 4948
Jay
In case anyone else is having this issue, I'm able to toss a variable into
my directorysearcher.filter with the following code -- This code gathers all
members of a particular group in Active Directory, finds their
samAccountName and populates a checkboxlist with these values:
'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")

'Get the members of the group

For Each Approvers_result In Approvers_entry.Properties("member")

Approvers_result = Approvers_result.ToString.Split(",")(0)

Approvers_result = Approvers_result.ToString.Split("=")(1)

'Find the samAccountName of the current Approvers_result

searcher.Filter = ("(&(objectClass=person)(cn=" & Approvers_result & "))")

result = searcher.FindOne

'Fill Approvers checkbox lists with member's samAccountName property

cblApprovers.Items.Add(New
ListItem(result.Properties("samAccountName")(0).To String))

Next
"Jay" <jg********@scf.sk.ca> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jayant Sane | last post: by
4 posts views Thread by cameron | last post: by
reply views Thread by dave | last post: by
1 post views Thread by Jay | last post: by
2 posts views Thread by dhnriverside | last post: by
4 posts views Thread by mike | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.