2016-03-31 25 views
2

特定のActive Directoryグループのユーザーの詳細を取得する必要があります。私はこのコードを使用しています:フィルターでActive Directoryグループのユーザー名をCで取得する

var result = grpResponse.Entries[0]; 

if (result.Attributes["member"] != null) 
{ 
    for (var i = 0; i < result.Attributes["member"].Count; i++) 
    { 
      var filter = result.Attributes["member"][i].ToString(); 

      var query = "(&(objectClass=user)(" + filter + "))"; // Here I need username to use like cn=username 

      var userRequest = new SearchRequest(distinguishedName, query, 
            SearchScope.Subtree); 

私は一人でこのCN値すなわちユーザー名を取ることができますどのように

CN=Name,OU=something,DC=example 

のようなものを取得していますか?

答えて

1

.NET 3.5以降の場合は、System.DirectoryServices.AccountManagement(S.DS.AM)名前空間を確認する必要があります。

基本的に、あなたはドメインコンテキストを定義し、簡単にADのユーザーおよび/またはグループを見つけることができます:

// set up domain context - limit to the OU you're interested in 
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, null, "OU=YourOU,DC=YourCompany,DC=Com")) 
{ 
    // find the group in question 
    GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere"); 

    // if found.... 
    if (group != null) 
    { 
     // iterate over the group's members 
     foreach (Principal p in group.GetMembers()) 
     { 
      Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName); 

      // do whatever else you need to do to those members 
     } 
    } 
} 

新しいS.DS.AMは、ADのユーザーとグループで遊んすることが本当に簡単になります!

ここでそれについて詳しく読む:

0

以下、私がまさに必要です。

あなたが持つかもしれ我々のように使用OuStringは、複数の部品を持っている - 両方のOU & DC

bstring OUString = "OU=Groups,OU=Accounts,DC=nw,DC=nos,DC=ourcompanyName,DC=com" ; 

using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, null, OUString)) 
関連する問題