Yeah that's the way I thought I'd have to do it, but thought there must be a better solution?!?!
Main Topics
Browse All TopicsHi,
I am having a problem searching Active directory to see if a user is a member of the group. The following code works just fine if the user is in the group you pass, but I need to search all subgroups as well? I am new to working with AD. Any help would be greatly appreciated.
This is what I have to search the current group.
public static ActiveDirectoryUserCollect
{
ActiveDirectoryUserCollect
DirectorySearcher userSearch = null;
DirectoryEntry userDE = null;
userSearch = ActiveDirectoryUtility.Cre
userSearch.PropertiesToLoa
userSearch.SearchScope = SearchScope.Subtree;
userSearch.Filter = "(&(objectCategory=group)(
userSearch.Sort = new SortOption("sn", SortDirection.Ascending);
SearchResult groupResult = userSearch.FindOne();
if (groupResult != null)
{
for (int groupIndex = 0; groupIndex < groupResult.Properties["me
{
userDE = new DirectoryEntry("LDAP://" + groupResult.Properties["me
if (userDE != null)
{
ActiveDirectoryUser user = new ActiveDirectoryUser();
user.ParentHashCode = users.GetHashCode();
user.AdsPath = userDE.Path;
user.givenName = GetPropertyCollectionStrin
user.sn = GetPropertyCollectionStrin
user.samAccountName = GetPropertyCollectionStrin
users.Add(user);
}
}
}
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: Chris-DentPosted on 2008-07-07 at 01:30:19ID: 21943374
You'll need to use a recursive test of group membership. I wrote something to do that in VbScript, it won't directly translate but perhaps it'll give you enough of an idea. I certainly don't know enough C# to write it in that :)
strGroup is the group you're testing, arrGroups is an array returned from the "memberOf" attribute. And x is a simple counter (not used for anything other than displaying output as a tree).
In essence, you pass the array through to a subroutine, loop through the contents of that array as a basic member of, and passing each sub-groups memberOf array back to the Subroutine.
It gets a bit hairy if you have to protect against circular nesting, hopefully you won't need to.
HTH
Chris
Select allOpen in new window