简体   繁体   English

获取OU的标准名称

[英]Get fully-qualified name of an OU

I have a code to get the list of OUs within a domain. 我有一个代码来获取域内OU的列表。

Now this just lists all the OUs and does not give any way to distinguish between an OU and a sub 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());
}

Is there a way i can get the fully qualified name of an OU? 有没有办法我可以获取OU的全限定名?

Something like this for a sub OU: 对于子OU来说是这样的:

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

Any help is appreciated... thanks 任何帮助表示赞赏...谢谢

temp.Path应该为您提供每个OU的专有名称。

Use the property Path from SearchResult , as in temp.Path , see link . 使用来自SearchResult的属性Path ,如temp.Path ,请参阅链接

The Path property uniquely identifies this entry in the Active Directory hierarchy. Path属性在Active Directory层次结构中唯一标识此条目。 The entry can always be retrieved using this path. 始终可以使用此路径来检索条目。

You can enumerate all the available properties with the following source code: 您可以使用以下源代码枚举所有可用属性:

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());
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM