By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,330 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,330 IT Pros & Developers. It's quick & easy.

Searching a Specific OU...

P: n/a
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.
Jan 29 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Joe" <Jo*@discussions.microsoft.comwrote in message
news:41**********************************@microsof t.com...
>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.

Jan 29 '07 #2

P: n/a
Willy,

Thanks. I had tried that, but was using the wrong format.

Works great.

"Willy Denoyette [MVP]" wrote:
"Joe" <Jo*@discussions.microsoft.comwrote in message
news:41**********************************@microsof t.com...
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.

Jan 29 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.