Hi I am using the following code to retrieve all the members of a specific active directory group. The code works but the problem is that the code returns all users in "distinguishedName" form which has a lot of extra info I don't need. I need the users to be displayed in "sAMAccountName" form. I have tried a lot of different search filters but none will display any information.
public ArrayList GetADGroupUsers()
{
// DataSet dset = new DataSet();
//DataTable dt = new DataTable();
// DataColumn dc = new DataColumn("Members");
//DataColumn dc1 = new DataColumn("CN");
// dt.Columns.Add(dc);
// dt.Columns.Add(dc1);
string group = "share_IT";
DirectoryEntry de = GetDirectoryObject();
SearchResult result;
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(cn={0})", group);
// search.Filter = "(&(objectClass=group)(sn=" + group + "))";
// search.PropertiesToLoad.Add("cn");
search.SearchRoot = de;
result = search.FindOne();
ArrayList userNames = new ArrayList();
if (result != null)
{
for (int counter = 0; counter <
result.Properties["member"].Count; counter++)
{
string user = (string)result.Properties["member"][counter];
userNames.Add(user);
}
}
return userNames;
}