【域控】获取域控用户

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.DirectoryServices;

namespace Domain
{
    public class DirectoryActive 
    {
        private void GetUser()
        {
            string path;
            path = "LDAP://OU=Users,OU=Beijing,OU=****,DC=**,DC=corp";
            
            List<string> userList = new List<string>();

            DirectoryEntry ent = new DirectoryEntry(path);
            foreach (DirectoryEntry child in ent.Children)
            {
                foreach (DirectoryEntry child1 in child.Children)
                {
                    if (child1.Properties["displayname"].Value != null && child1.Properties["mailNickname"].Value != null)
                    {
                        string user = String.Format("{1}:{0}", child1.Properties["displayname"].Value.ToString(), child1.Properties["mailNickname"].Value.ToString());
                        userList.Add(user);
                    }
                }
            }
            foreach (string str in userList)
            {
                Console.WriteLine(str);
            }
            
        }
    }
}
原文地址:https://www.cnblogs.com/viewcozy/p/4688283.html