Searching a Specific OU...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have some code that works great, however it returns all
Groups within AD, but I only need it to return Groups that
are in a Specific OU.

I tried setting a filter on the search to that OU's DN, but then
it only returned that DN.

What's the best way using what I currently have?

Here's the basic code...

DirectoryEntry entry = new DirectoryEntry("LDAP://ww.xx.yy.zz","Username",
"Password", AuthenticationTypes.Secure);

DirectorySearcher dSearch = new DirectorySearcher(entry);
dSearch.Filter = "(&(objectClass=group))";

foreach(SearchResult sResultSet in dSearch.FindAll())
{
WHAT TO DO
}

That's the gist of it.

Any pointers would be appreciated.
 
Joe said:
I have some code that works great, however it returns all
Groups within AD, but I only need it to return Groups that
are in a Specific OU.

I tried setting a filter on the search to that OU's DN, but then
it only returned that DN.

What's the best way using what I currently have?

Here's the basic code...

DirectoryEntry entry = new DirectoryEntry("LDAP://ww.xx.yy.zz","Username",
"Password", AuthenticationTypes.Secure);

DirectorySearcher dSearch = new DirectorySearcher(entry);
dSearch.Filter = "(&(objectClass=group))";

foreach(SearchResult sResultSet in dSearch.FindAll())
{
WHAT TO DO
}

That's the gist of it.

Any pointers would be appreciated.


Set the OU as root of the object your are binding to ...

DirectoryEntry entry = DirectoryEntry(LDAP://domain/ou=SomeOU, DC=xxx,DC=yyy,DC=zzz", ...;

Willy.
 
Back
Top