1

ドメイン内の 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

どんな助けでも大歓迎です...ありがとう

4

2 に答える 2

1

のように のプロパティPathを使用します。リンクを参照してください。SearchResulttemp.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());
    }
}
于 2011-04-04T21:08:11.477 に答える