Problem with Searching Groups in Active Directory

C

Cathie

Hi All,

I am trying to use DirectorySearch and it is just not working for me. I
have the following ActiveDirectory structure:

TestGroup (group)
-> TestUser (user)
-> TestAdministrators(group)
-> Development Team (group)
-> DevA (user)
-> DevB (user)
-> DevC (user)

Where -> represents "member of "

I am trying to get the list of Groups and Users from TestGroup which to my
reckoning should be TestUser and TestAdministrators, but if I use
SearchScope.SubTree I get "TestGroup" but nothing else, and if I use
SearchScope.OneLevel I don't get anything.

What is wrong with this code?

DirectoryEntry group = new
DirectoryEntry("LDAP://CN=TestUsers,CN=Users,DC=comp,DC=company,DC=com");
object members = group.Invoke("Members",null);
foreach(object member in (IEnumerable) members)
{
if (str != String.Empty)
{
str += ", ";
}
DirectoryEntry x = new DirectoryEntry(member);
str += x.Name.ToString() + ": " + x.SchemaClassName;
}

DirectorySearcher src = new DirectorySearcher(group);
src.Filter = "(objectClass=*)";
src.SearchScope = SearchScope.OneLevel;
SearchResultCollection resultColl = src.FindAll();
DirectoryEntry result;
string[,] memberList = new string[resultColl.Count, 2];
foreach (SearchResult child in resultColl)
{
result = child.GetDirectoryEntry();
memberList[0,0] = result.Name.ToString();
if (result.SchemaClassName.ToUpper() == "GROUP")
{
memberList[0,1] = "GROUP";
}
else if (result.SchemaClassName.ToUpper() == "USER")
{
memberList[0,1] = "USER";
}
}

Note: The "members" call gets back what I want, but I believe there is
issues with this with large numbers of users so was trying to do this the
right way.

Thanks in advanced,
Cathie
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top