Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# active directory
Hi,
 
I want get all user from particular security group. This Group present in Active directory.
 
I want filter condition for this and also I need C sharp code to do it same.
 
I am trying following Filter criteria:
 
(&(objectCategory=group)(SAMAccountName=" + txtusername.Text + "))
 

But it return only security group, I want user of this security group.
 

Thanks in Advance.
Posted 29-May-13 3:03am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

class ActiveDirectory
    {
        public ActiveDirectory()
        {
            //PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Machine); //Connecting to local computer.
            //PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain, "MPTDC1-INDIA", "DC=MPTDC1-INDIA,DC=com"); //Connecting to Active Directory
            //PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Machine, "TAMERO", "administrator", "password"); //Connecting to local computer with credentials of an user

        }
 
        public void GetUsers()
        {
            PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain, "MPTDC1-INDIA");
 
            UserPrincipal insUserPrincipal = new UserPrincipal(insPrincipalContext);
            insUserPrincipal.Name = "*";
            SearchUsers(insUserPrincipal);
        }
 
        private void SearchUsers(UserPrincipal parUserPrincipal)
        {
            PrincipalSearcher insPrincipalSearcher = new PrincipalSearcher();
            insPrincipalSearcher.QueryFilter = parUserPrincipal;
            PrincipalSearchResult<Principal> results = insPrincipalSearcher.FindAll();
            foreach (Principal p in results)
            {
                Console.WriteLine(p.DisplayName);
            }
        }
    }
 
class Program
    {
        static void Main(string[] args)
        {
            var ad = new ActiveDirectory();
            ad.GetUsers();
        }
    }
 
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 428
1 Maciej Los 249
2 BillWoodruff 199
3 /\jmot 180
4 Suraj Sahoo | Coding Passion 150
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 29 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100