private void LoadAdGroupMemberDetails(string group) { using (DirectorySearcher searcher = new DirectorySearcher()) { searcher.PropertiesToLoad.AddRange(new string[] { "objectSid", "sAMAccountName", "distinguishedName" }); searcher.Filter = string.Format("(&(ObjectClass=Group)(CN={0}))", group); object memberResults = searcher.FindOne().GetDirectoryEntry().Invoke("members"); foreach (object member in (IEnumerable)memberResults) { string[] properties = new string[7]; using (DirectoryEntry dEntry = new DirectoryEntry(member)) { string type = dEntry.InvokeGet("class").ToString(); string account = dEntry.Properties["sAMAccountName"].Value.ToString(); if (type.ToLower() == "user") { LoadAdUserDetails(account, group); } else if (type.ToLower() == "group") { AdGroups.Add(account); } } } } }
public void Load() { GetLocalAdminsistrators(Server); foreach (string[] admin in LocalAdmins) { string account = admin[(int)DC.SAM_ACCOUNT]; string type = admin[(int)DC.OBJECT_TYPE]; if (type == "localuser" || type == "localgroup") { Persons.Add(admin); } else if (type == "aduser") { LoadAdUserDetails(account, Server); } else if (type == "adgroup") { LoadAdGroupMemberDetails(account); } } for (int i = 0; i < AdGroups.Count; i++) /* loop to get all leaf person members of parent group */ { LoadAdGroupMemberDetails(AdGroups[i]); AdGroups.RemoveAt(i); } Results.BeginLoadData(); foreach (string[] person in Persons) { Results.LoadDataRow(person, true); } Results.EndLoadData(); }