繁体   English   中英

查询具有自定义属性的所有用户的Active Directory

[英]Query the Active Directory for all users with a custom attribute

我要使用自定义UserPrincipalEx类,因为我想在Active Directory中查询自定义属性“ costCenter”。 因此,自定义UserPrincipalEx-Class添加了DirectoryProperty(“ costCenter”)。 基本且长时间运行(3分钟)的版本如下所示:

// create domain context
PrincipalContext context = new PrincipalContext(ContextType.Domain, "myDomainController");

// define the query-by-example principal
UserPrincipal qbeUser = new UserPrincipal(context);

// create the principal searcher    
PrincipalSearcher searcher = new PrincipalSearcher(qbeUser);

// find all matches
foreach (var hit in searcher.FindAll())
{
    //do incredible stuff here
}

现在,使用针对自定义属性“ costCenter”扩展的自定义类“ UserPrincipalEx”:

UserPrincipalEx qbeUser = new UserPrincipalEx(context);
qbeUser.costCenter = "123";

使查询的执行速度几乎与light一样快。 但是我真正需要的是查询仅具有 costCenter的所有用户(并非所有人都这样做)。

所以我的问题是: 如何使用扩展的“按示例查询”主体来搜索仅具有自定义属性的主体?

我恢复使用

Parallel.ForEach 

为了加快整个过程。 ForEach-Loop在IEnumerable上运行,该IEnumerable具有我感兴趣的自定义属性的所有值,使用这些值之一对UserPrincipalEx属性进行修饰,然后将结果添加到列表中。

并不是我真正想要的,而是有效的:从3分钟到15秒。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM