Вы можете использовать PrincipalSearcher
и «запрос по образцу» принципал сделать ваш поиск:
// create your domain context
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
{
// define a "query-by-example" principal - here, we search for all "enabled" UserPrincipal
UserPrincipal qbeUser = new UserPrincipal(ctx);
qbeUser.IsEnabled = true;
// create your principal searcher passing in the QBE principal
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.....
}
}
Если вы еще не - абсолютно читать статью MSDN Managing Directory Security Principals in the .NET Framework 3.5, который показывает хорошо, как сделать лучшее использование новых функций в System.DirectoryServices.AccountManagement
. Или просмотрите пространство имен .