0

I'm using a custom UserPrincipalEx-class since I want to query the Active Directory for a custom attribute "costCenter". The custom UserPrincipalEx-Class therefore has a DirectoryProperty("costCenter") added. The basic and long-running (3 minutes) version looks like this:

// 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
}

Now, using a customized class "UserPrincipalEx" that is extended for the custom attribute "costCenter":

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

makes the query execute almost as fast as light. But what I really need would be to query for all users that just have a costCenter (not all do so).

So my question is: How to use an extended "Query-By-Example" principal to search for principals that just have a custom attribute?

4

1 回答 1

0

我恢复使用

Parallel.ForEach 

为了加快整个过程。ForEach-Loop 在 IEnumerable 上运行,其中包含我感兴趣的自定义属性的所有值,使用这些值之一来完善 UserPrincipalEx 属性并将结果添加到列表中。

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

于 2013-09-26T07:30:29.013 回答