udir
asked on
Active Directory filter syntax....
Hi,
I need to get all the objectClass which are = user
and the OU match a variant i compare to.
I wrote:
search.Filter = "(&(objectClass=user)(OU=_ VAR))";
but the search result get nothing. (_VAR is a variant in which i pass a string).
What is the right syntax??
Thanks
I need to get all the objectClass which are = user
and the OU match a variant i compare to.
I wrote:
search.Filter = "(&(objectClass=user)(OU=_
but the search result get nothing. (_VAR is a variant in which i pass a string).
What is the right syntax??
Thanks
ASKER
Hi,
Thanks for the reply.
I forgot to mention - C#,
OK, i wrote -
search.Filter = "(&(objectClass=user)(OU=" + _VAR+ "))";
but i get nothing.
If i put the filter in the LDAP it's OK -
DirectoryEntry root = new DirectoryEntry("LDAP://10. 1.1.1/OU=" + _VAR + ",DC=Internet,DC=Ladpc",
"User", "Pass", AuthenticationTypes.Server Bind);
DirectorySearcher search = new DirectorySearcher(root);
search.Filter = "(&(objectClass=user))";
Any Idea?
Thanks for the reply.
I forgot to mention - C#,
OK, i wrote -
search.Filter = "(&(objectClass=user)(OU="
but i get nothing.
If i put the filter in the LDAP it's OK -
DirectoryEntry root = new DirectoryEntry("LDAP://10.
"User", "Pass", AuthenticationTypes.Server
DirectorySearcher search = new DirectorySearcher(root);
search.Filter = "(&(objectClass=user))";
Any Idea?
Im not sure you can filter on ou the way you are trying to...
but as you said if you add the ou in to the adspath then its working so you can just use that
Scott
but as you said if you add the ou in to the adspath then its working so you can just use that
Scott
ASKER
My problem is that i need to move the LDAP path to the app.config.
i wrote (at the app.config) :
<activeDirectorySettings defaultServer="Test">
<servers>
<clear />
<add host="10.1.1.1" namingContext="DC=Internet ,DC=Ladpc" userName="User" password="Password" name="Test" AuthenticationTypes="Serve rBind" />
</servers>
</activeDirectorySettings>
And my problem is that i don't know how to pass a variant (_VAR) to the app.config.
If i will succeed doing it in this way, it will solve my problem!!
Can you help with that? (I mean - pass a variant to app.config - if it is possible)
Thanks
i wrote (at the app.config) :
<activeDirectorySettings defaultServer="Test">
<servers>
<clear />
<add host="10.1.1.1" namingContext="DC=Internet
</servers>
</activeDirectorySettings>
And my problem is that i don't know how to pass a variant (_VAR) to the app.config.
If i will succeed doing it in this way, it will solve my problem!!
Can you help with that? (I mean - pass a variant to app.config - if it is possible)
Thanks
so what does your code snippet look like when it is using the app.config file?
Scott
Scott
search.Filter = String.Format("(&(objectCl ass=user)( dn=*OU={0} *))", _VAR);
This should work, since the OU should be a part of the DN of the object. Remember to set the search scope to Subtree.
This should work, since the OU should be a part of the DN of the object. Remember to set the search scope to Subtree.
ASKER
Rytmis, sorry i steel get nothing.
Colosseo - it looks like that -
public static string ADconnectionString = ConfigurationManager.AppSe ttings["Te st"];
DirectoryEntry root = new DirectoryEntry(DataComm.AD connection String);
Colosseo - it looks like that -
public static string ADconnectionString = ConfigurationManager.AppSe
DirectoryEntry root = new DirectoryEntry(DataComm.AD
Rytmis could be on to the solution you need
try adspath instead of dn:
search.Filter = String.Format("(&(objectCl ass=user)( adspath=*O U={0}*))", _VAR);
try adspath instead of dn:
search.Filter = String.Format("(&(objectCl
ASKER
Sorry guys it just dosn't retrieve anything, ( Thanks for the effort (: )
my code is :
-------------------------- ---------- ---------- ---------- ------
public static string ADconnectionString = ConfigurationManager.AppSe ttings["Te st"];
DirectoryEntry root = new DirectoryEntry(DataComm.AD connection String);
DirectorySearcher search = new DirectorySearcher(root);
search.SearchScope = SearchScope.Subtree;
search.Filter = String.Format("(&(objectCl ass=user)( ADsPath=*O U={0}*))", _VAR);
search.PropertiesToLoad.Ad d("Name");
search.PropertiesToLoad.Ad d("ID");
SearchResult result;
SearchResultCollection resultCol = search.FindAll();
string[] allUsers = new string[resultCol.Count];
string[] allID = new string[resultCol.Count];
if (resultCol != null)
{
for(int counter=0; counter < resultCol.Count; counter++)
-------------------------- ---------- ---------- ---------- ---------- ---------- --------- and so on....
Count allways = 0 !! , but again, if i put the " OU=_VAR " at the LDAP it's OK.
What else can i do???
my code is :
--------------------------
public static string ADconnectionString = ConfigurationManager.AppSe
DirectoryEntry root = new DirectoryEntry(DataComm.AD
DirectorySearcher search = new DirectorySearcher(root);
search.SearchScope = SearchScope.Subtree;
search.Filter = String.Format("(&(objectCl
search.PropertiesToLoad.Ad
search.PropertiesToLoad.Ad
SearchResult result;
SearchResultCollection resultCol = search.FindAll();
string[] allUsers = new string[resultCol.Count];
string[] allID = new string[resultCol.Count];
if (resultCol != null)
{
for(int counter=0; counter < resultCol.Count; counter++)
--------------------------
Count allways = 0 !! , but again, if i put the " OU=_VAR " at the LDAP it's OK.
What else can i do???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great thanks it works!
search.Filter = "(&(objectClass=user)(OU="
Scott