从Active Directory获取用户列表 [英] Get User List from Active Directory

查看:95
本文介绍了从Active Directory获取用户列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我希望得到特定安全组的所有用户。这个组出现在Active目录中。



我想要这个过滤条件,我也需要C代码才能这样做。



我正在尝试以下过滤条件:



(&(objectCategory = group)(SAMAccountName =+ txtusername.Text +))< br $> b $ b



但它只返回安全组,我想要这个安全组的用户。





先谢谢。

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.

推荐答案

这里有一些链接可以帮助你:

< a href =http://blogs.technet.com/b/brad_rutkowski/archive/2008/04/15/c-getting-members-of-a-group-the-easy-way-with-net-3- 5-discussion-groups-nested-recursive-security-groups-etc.aspx> C#:使用.Net 3.5(讨论组,嵌套,递归,安全组等)轻松获取组成员 [ ^ ]

使用C#检索Active Directory组中的所有用户 [ ^ ]



祝你好运,

OI
Here are some links to help you:
C#: Getting members of a group the easy way with .Net 3.5 (Discussion groups, nested, recursive, security groups, etc.)[^]
Retrieve all the users in an Active Directory group using C#[^]

Good luck,
OI


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();
        }
    }


这篇关于从Active Directory获取用户列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆