Searching a Specific OU...

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.
 
W

Willy Denoyette [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top