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 members
foreach (Principal p in group.GetMembers())
{
UserPrincipal up = p as UserPrincipal;
if (up != null)
{
Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);
// do whatever you need to do with that user principal
}
}
}
}
あなたは、グループのメンバーシップからだけユーザーを取得することはできません - あなたはフィルタリングする必要があるあなたが取得した後結果は戻ってくる。
新しいS.DS.AMは、ADのユーザーやグループで本当に簡単に遊べます!
ここでそれについて詳しく読む:
を使用すると、ユーザーがグループを区別する方法は? – Adil
ユーザーにはエントリとグループがありません。だから私は例外をユーザーの詳細を追加中に取得しています。 – Shesha
例外が発生する行は何ですか?ループはどちらもコンパイルされませんが、完全なコードですか? – Adil