473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 5258
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jayant Sane | last post by:
I am trying to search a user object that is located in a domain that is sub-ordinate to the one from where I begin my search. For eg. I have the domains as DC=corp,DC=company,DC=com and...
5
by: Dave | last post by:
Hi All C# ADSI samples that I run cause unspecified errors. If I translate them into VB.NET they run fine. Here's an example: public string getEmail(string LDAPPath, string username) {...
4
by: cameron | last post by:
I have always been under the impression that LDAP was optimized for speed. Fast queries, fast access, slower writes. I have a block of data in LDAP and in SQL. Exact same data. The query is fast...
0
by: dave | last post by:
does anyone know how to create a "Not Equal To" DirectorySearcher.Filter Property? "<>" and "!=" don't seem to work. For example, I want Searcher.filter = ("(displayname<>Template)"). ...
1
by: Jay | last post by:
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...
2
by: dhnriverside | last post by:
Hi I'm getting the following error in my code... "Exception Details: System.Runtime.InteropServices.COMException: The server does not support the requested critical extension" Here's the...
4
by: mike | last post by:
I'm needing a bit of help to fine tune my Filter property for a DirectorySearcher. My context here is for a company phone directory. A user enters the string they want to search for (in txtSearch)...
0
by: LiQuick | last post by:
Dear Reader, When I try to run the following LDAP filter with the DirectorySearcher it doesn't return any OU's but when I use it with Active Directory Users and Computers it returns the desired...
2
by: Jim in Arizona | last post by:
I'm trying to do a check to see if a specific active directory user account exists in active directory AND a specific group. I can't seem to get the filter down right. I can do this to find a...
6
by: Zetten | last post by:
I have an AD search module which works as I want it to; searching for a matching forename and/or surname in the appropriate OU. I would like to extend it to be more flexible, so that instead of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.