2016-08-24 2 views
0

に保存like:反復グループと、私はADのうち、ユーザノードを取得する手順を持っているリスト

foreach (ResultPropertyValueCollection s in result.Properties.Values) 
{ 
    string groupname = null; 

    for (int i = 0; i < s.Count; i++) 
    { 
     dn = s[i].ToString(); 
     equalsIndex = dn.IndexOf("=", 1); 
     commaIndex = dn.IndexOf(",", 1); 

     groupname = dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1); 

     lstGroups.Add(groupname); 
    } 
} 

「DirectorySearcher」クラスで使用できる方法はありますか?

また、最初のHashtableを削除する方法はありますか? SearchResultオブジェクトのadspathオブジェクトです。

答えて

0

自分で識別名を解析する代わりに、DirectoryEntryオブジェクトを使用して、表示名をADに問い合わせることができます。例:

var directoryEntry = new DirectoryEntry(@"LDAP://address"); 
var directorySearcher = new DirectorySearcher(directoryEntry); 
directorySearcher.Filter = "samaccountname=user"; 
directorySearcher.PropertiesToLoad.Add("memberOf"); 
var result = directorySearcher.FindOne(); 
foreach (var i in result.Properties["memberOf"]) 
{ 
    var group = new DirectoryEntry(@"LDAP://" + i); 
    Console.WriteLine(group.Properties["DisplayName"]); 
} 
+1

はい、ありがとうございました。 DirectoryEntryクラスの詳細を読む予定です。 +1し、答えとしてマークします。 – user3442470

関連する問題