2

I have some code that retreive the users present in different groups in Active directory.

string sADPath = "LDAP://" + tbDomain.Text;
string username = tbUsername.Text;
string password = tbPassword.Text;
DirectorySearcher mySearcher = new DirectorySearcher(directoryEntry);


int MaxResults = Int32.MaxValue - 1;


ComboBoxItem selectItem = (ComboBoxItem)ddlGroups.SelectedItem;
String value = selectItem.Value;

mySearcher.Filter = ("(&(objectCategory=person)(objectClass=User)(memberOf=" + value + "))");

mySearcher.SearchScope = SearchScope.Subtree;


foreach (SearchResult temp in mySearcher.FindAll())
{
}

This code works fine for some groups but not for all.

For example it gets me the values of Domain Admins but not users within Domain Users.

It will also not get my users in the Users folder group?

I get 0 value for Domain users at FindAll().

JPBlanc
  • 70,406
  • 17
  • 130
  • 175
user175084
  • 4,550
  • 28
  • 114
  • 169

1 Answers1

4

You are encountering different problems.

The fact you can't find any user member of Domain Users is explained by the fact that Domain Users is the default primary group of each new user you create. The primarygroup is not present in memberof Attribute but in primaryGroupID attribute. Even more primaryGroupID is not a distinguised name but just the Relative Identifier (RID) of the primary group. You will find the C# code in the answer I wrote to : How to retrieve Users in a Group, including primary group users

Community
  • 1
  • 1
JPBlanc
  • 70,406
  • 17
  • 130
  • 175