PrincipalSearcher
および「例によるクエリ」プリンシパルを使用して検索を行うことができます。
// create your domain context
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
{
// define a "query-by-example" principal - here, we search for a UserPrincipal
// and with the first name (GivenName) of "Jinal*"
UserPrincipal qbeUser = new UserPrincipal(ctx);
qbeUser.GivenName = "Jinal*";
// create your principal searcher passing in the QBE principal
using (PrincipalSearcher srch = new PrincipalSearcher(qbeUser))
{
// find all matches
foreach(var found in srch.FindAll())
{
// do whatever here - "found" is of type "Principal" -
// it could be user, group, computer.....
}
}
}
まだお読みでない場合は、.NET Framework 3.5でディレクトリ セキュリティ プリンシパルを管理するという MSDN の記事を必ずお読みくださいSystem.DirectoryServices.AccountManagement
。または、System.DirectoryServices.AccountManagement 名前空間に関する MSDN ドキュメントを参照してください。
もちろん、必要に応じて、作成した「例によるクエリ」ユーザー プリンシパルに他のプロパティを指定することもできます。
DisplayName
(通常: 名 + スペース + 姓)
SAM Account Name
- Windows/AD アカウント名
User Principal Name
- "username@yourcompany.com" スタイル名
の任意のプロパティを指定し、UserPrincipal
それらを の「例によるクエリ」として使用できますPrincipalSearcher
。