DirectoryEntry Properties

本文关键字:Properties DirectoryEntry | 更新日期: 2023-09-27 18:25:04

我对我的C#项目有一个简短的请求。我想读出我们的活动目录并使用这个:

System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);
foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
{
        System.DirectoryServices.DirectoryEntry de = resEnt.GetDirectoryEntry();
        try
        {
            myRow["eMail"] = de.Properties["Mail"].Value.ToString();
        }
        catch (Exception)
        { }
}

现在我想读出其他属性,希望你能给我一份所有属性的列表。

感谢

DirectoryEntry Properties

您可以通过下面的代码来完成

 DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);
            foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll())
            {
                try
                {
                    foreach (string property in resEnt.Properties.PropertyNames)
                    {
                        string value = resEnt.Properties[property][0].ToString();
                        Console.WriteLine(property + ":" + value);
                    }
                }
                catch (Exception)
                { }
            }