If you pass the groupName to this method, it will return the list of all memebers available in this group.
using System;
using System.DirectoryServices;
using System.Security.Principal;
using System.Runtime.InteropServices;
using System.Collections;
public System.Collections.ArrayList GetADGroupUsers(string groupName)
{
SearchResult result;
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(cn={0})", groupName);
search.PropertiesToLoad.Add("member");
result = search.FindOne();
ArrayList userNames = new ArrayList();
if (result.Properties["member"] != null)
{
for (int counter = 0; counter <
result.Properties["member"].Count; counter++)
{
string user = (string)result.Properties["member"][counter];
string[] userdetail;
string delimStr = ",";
char [] delimiter = delimStr.ToCharArray();
userdetail=user.Split(delimiter,3);
user=userdetail[0].Remove(0,3);
userNames.Add(user);
}
}
return userNames;
}


No comments:
Post a Comment