dotnet - Get All Active Directory Users in a Group
Use the following handy method to get all users in an AD group .NET 3.5 Add a reference to System.DirectoryServices.AccountManagement public static List<UserPrincipal> GetAllUsersInGroup(string domain, string groupname) { List<UserPrincipal> result = new List<UserPrincipal>(); using (var context = new PrincipalContext(ContextType.Domain, domain)) using (var group = GroupPrincipal.FindByIdentity(context, groupname)) { if (group != null) { result.AddRange(group.GetMembers(true).Cast<UserPrincipal>().ToList()); } } return result; } private static string GetADStatus(int inputField) { // Assume the user is disabled string result = "Disabled"; // Declare the hex for the accountDisabled flag int accountDisabled = 0x00000002; // https://msdn. [Read more...]