Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取OU的完全限定名_C#_Asp.net_Active Directory_Ldap_Ou - Fatal编程技术网

C# 获取OU的完全限定名

C# 获取OU的完全限定名,c#,asp.net,active-directory,ldap,ou,C#,Asp.net,Active Directory,Ldap,Ou,我有一个代码来获取域内的OU列表 现在,这只是列出了所有OU,并没有给出任何方法来区分OU和子OU DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain); DirectorySearcher mySearcher = new DirectorySearcher(entry); mySearcher.Filter = ("(objectClass=organizationalUnit)"); foreach (SearchR

我有一个代码来获取域内的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

感谢您的帮助。。。谢谢

temp.Path
应该为您获取每个OU的可识别名称。

temp.Path
应该为您获取每个OU的可识别名称。

使用
搜索结果
中的属性
Path
,如
temp.Path
中所述,请参阅

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

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

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 101hey非常感谢。。有没有办法将上面的字符串显示为businessunit/department 101hey Thank buddy但是有没有办法将上面的完全限定名“CN=Computer1,OU=department 101,OU=businessunit#1,DC=us,DC=xyz,DC=com”显示为。。businessunit/department 101
string.Join(“/”,temp.Path.Split(“,”).Select(s=>s.StartsWith(“OU”).Reverse().ToArray())
hey Thank buddy buddy,但是有没有办法将上面的完全限定名“CN=Computer1,OU=department 101,OU=businessunit#1,DC=us,DC=xyz,DC=com”显示为。。业务单元/部门101
string.Join(“/”,temp.Path.Split(“,”)。选择(s=>s.StartsWith(“OU”)。Reverse().ToArray())