从远程Active Directory获取用户列表 [英] Get UserList From Remote Active Directory

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

问题描述

你好

有什么方法可以使用C#从远程活动目录服务器获取用户列表吗?

Is there any way I can get user list from remote active directory server using C# ?

推荐答案

Hi Tech Aspirant,

Hi Tech Aspirant,

谢谢您在这里发布.

对于您的问题,您可以尝试以下代码.这个对我有用.它将获取域中的所有用户供您参考.

For your question, you could try the following code. It works for me. It will get all the user in Domain for your reference.

  public static void GetAD()
        {
            List<string> userNameList = new List<string>();
            using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
            {
                using (UserPrincipal user = new UserPrincipal(context))
                {
                    using (PrincipalSearcher searcher = new PrincipalSearcher(user))
                    {
                        foreach (System.DirectoryServices.AccountManagement.UserPrincipal result in searcher.FindAll())
                        {
                            userNameList.Add(result.Name);//put all the users in the list
                            Console.WriteLine(result.Name);//or you could output all the user name
                        }

                    }
                }
            }
        }

这是一种使所有用户都位于同一域中的简单方法.

It is a simple way to get all the user in same domain.

我希望这会有所帮助.

最好的问候,

温迪


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

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