我们有一个很大的LDAP目录,我们目前正在返回所有用户。我们遍历用户列表,比较我们在本地保存的内容,找到不再存在的或新的内容,然后在本地创建/删除它们。搜索DirectoryServices以按日期返回修改的用户列表
问题是此操作需要小时完成。
我认为解决方案是为目录服务定义一个更具体的搜索查询,并且只返回那些在过去24小时内(或者它最后一次运行时)被修改过的用户。不幸的是,我很难找到使用哪个属性来使搜索查询更具体。
我看过this list of available properties,但我看到的可能是'ms-DFS-Last-Modified-v2',但我不确定如何使用它。
还有其他想法吗?
我们使用目前搜索的代码如下:
PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, "MYDOMAIN", "dc=MYDOMAIN,dc=co,dc=za");
UserPrincipal theuser = new UserPrincipal(domainContext);
theuser.Name = "*";
// create a principal searcher for running a search operation
PrincipalSearcher pS = new PrincipalSearcher(theuser);
// assign the query filter property for the principal object
pS.QueryFilter = theuser;
// run the query
PrincipalSearchResult<Principal> theresults = pS.FindAll();
retUsers = new List<ActiveDirectoryUser>();
List<UserPrincipal> copyUsers = new List<UserPrincipal>();
copyUsers = theresults.OfType<UserPrincipal>().Where(userresult => userresult.EmailAddress != null).ToList();
foreach (UserPrincipal result in copyUsers)
{
... process users.
}
- >我有几乎相似的要求。这是一个旧的帖子,但你可以张贴一些样本如何使用C#AD查询来检索自日期以来修改的项目?另外,它是否也会返回已删除的项目? – user2107373
该查询是基于您要使用的属性过滤器创建的。类似于'dirSearcher.Filter =“(&(PROPERTYNAME =”+ VALUE +“))”;'。将PROPERTYNAME替换为实际的AD属性,然后显示您提供的值。阅读https://msdn.microsoft.com/en-us/library/aa746475(v=vs.85).aspx –