Click here to Skip to main content
13,090,299 members (89,648 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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 2:03am
Rate this: bad
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 = "*";
        private void SearchUsers(UserPrincipal parUserPrincipal)
            PrincipalSearcher insPrincipalSearcher = new PrincipalSearcher();
            insPrincipalSearcher.QueryFilter = parUserPrincipal;
            PrincipalSearchResult<Principal> results = insPrincipalSearcher.FindAll();
            foreach (Principal p in results)
class Program
        static void Main(string[] args)
            var ad = new ActiveDirectory();

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 29 May 2013
Copyright © CodeProject, 1999-2017
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