获取OU的完全限定名称



我有一个代码来获取域内的ou列表。

现在,这只是列出了所有OU,并没有给出任何区分OU和子OU的方法。

DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=organizationalUnit)");
foreach (SearchResult temp in mySearcher.FindAll())
{
   OU_DownList.Items.Add(temp.Properties["name"][0].ToString());
}

是否有一种方法可以获得OU的完全限定名称?

类似于sub OU:

CN=Computer1,OU=Department 101,OU=Business Unit #1,DC=us,DC=xyz,DC=com

任何帮助都是感激的…由于

temp.Path应该得到每个OU的distinguishedName。

使用SearchResultPath属性,如temp.Path,参见链接。

Path属性唯一标识此条目在活动目录中层次结构。条目总是可以是使用此路径检索。

您可以用下面的源代码枚举所有可用的属性:

foreach(string propKey in temp.Properties.PropertyNames)
{
    // Display each of the values for the property identified by
    // the property name.
    foreach (object property in temp.Properties[propKey])
    {
        Console.WriteLine("{0}:{1}", propKey, property.ToString());
    }
}

最新更新