帮助类-AD域操作

原文链接: http://www.cnblogs.com/a14907/p/6689147.html
 private static void GetAllUsersInAD()
        {
            DirectorySearcher searcher = new DirectorySearcher();

            searcher.SearchRoot = new DirectoryEntry("LDAP://a14907.com", "username", "pwd", AuthenticationTypes.Encryption);
            searcher.Filter = "(objectClass=USER)";

            searcher.SearchScope = SearchScope.Subtree;
            searcher.Sort = new SortOption("name", SortDirection.Ascending);
            searcher.PageSize = int.MaxValue - 100;

            searcher.PropertiesToLoad.AddRange(new string[] { "samaccountname", "company", "department", "mail" });

            SearchResultCollection results = searcher.FindAll();
            foreach (SearchResult item in results)
            {
                //操作
            }
        }

转载于:https://www.cnblogs.com/a14907/p/6689147.html

猜你喜欢

转载自blog.csdn.net/weixin_30302609/article/details/94797513