711 8/20/2015 1:59:55 AM


:
using System;
using System.DirectoryServices.AccountManagement;

namespace Working_With_Active_Directory
{
    class Program
    {
        static void Main(string[] args)
        {
            GetUsersList("DOMAIN", @"AD-GROUP-NAME");
            Console.ReadLine();
        }

        static void GetUsersList(string domainName, string groupName)
        {
            Console.WriteLine("=============Start " + groupName + "==================");
            using (var context = new PrincipalContext(ContextType.Domain, domainName))
            {
                using (var group = GroupPrincipal.FindByIdentity(context, groupName))
                {
                    if (group == null)
                    {
                        Console.WriteLine("Group does not exist");
                    }
                    else
                    {
                        var users = group.GetMembers(true);
                        foreach (UserPrincipal user in users)
                        {
                            Console.WriteLine(user.ToString());
                        }
                    }
                }
            }
            Console.WriteLine("=============End " + groupName + "==================");
        }
    }
}