【问题标题】:Get fully-qualified name of an OU获取 OU 的完全限定名称
【发布时间】:2011-04-04 20:30:32
【问题描述】:

我有一个获取域内 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 的完全限定名称?

类似这样的子 OU:

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

感谢任何帮助...谢谢

【问题讨论】:

    标签: c# asp.net active-directory ldap ou


    【解决方案1】:

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

    【讨论】:

    • 嘿,谢谢哥们,但有没有办法显示上述完全限定名称“CN=Computer1,OU=Department 101,OU=Business Unit #1,DC=us,DC=xyz,DC= com" as.. businessunit/department 101
    • string.Join("/",temp.Path.Split(',').Select(s=>s.StartsWith("OU")).Reverse().ToArray())
    【解决方案2】:

    使用SearchResult 中的属性Path,如temp.Path,请参阅link

    Path 属性唯一标识 Active Directory 中的此条目 等级制度。条目总是可以 使用此路径检索。

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

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

    【讨论】:

    • 嘿,非常感谢.. 有没有办法将上述字符串显示为 businessunit/department 101
    猜你喜欢
    • 2016-09-30
    • 2018-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 2016-06-30
    相关资源
    最近更新 更多