首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于Active中查询的PrincipalContext

用于Active中查询的PrincipalContext
EN

Stack Overflow用户
提问于 2013-01-18 21:39:35
回答 1查看 18.6K关注 0票数 3

我想从中做一些简单的报告。在讨论之后,我发现如果我使用.NET FW3.5和更高版本,使用PrincipalContext是合适的。我想了解原理,以及我能用这个新特性做些什么(不像DirectoryEntry)。

代码骨架

代码语言:javascript
复制
// create your domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, 
    "YOURDOMAIN", "OU=SomeOU,DC=YourCompany,DC=com");

// define a "query-by-example" principal - here, we search for a UserPrincipal 
// which has a password that will expire in 3 days or less
UserPrincipal userTemplate = new UserPrincipal(ctx);
userTemplate.AdvancedSearchFilter.AccountExpirationDate(DateTime.Today.AddDays(3), MatchType.LessThanOrEquals);

// instantiate searcher
PrincipalSearcher searcher = new PrincipalSearcher(userTemplate);

// enumerate matching users
foreach (Principal foundPrincipal in searcher.FindAll())
{
    UserPrincipal foundUser = (foundPrincipal as UserPrincipal);

    if (foundUser != null)
    {
        // do something with users found - e.g. send e-mail
    }
}

可以通过代码向上添加此属性以便登录到LDAP:

  • 使用什么LDAP (版本2或3)
  • 如何设置运行LDAP的端口
  • 如果我需要SSL连接,该如何工作?(不同的港口,必须有特殊要求)

此外,我能用AdvancedSearchFilter做这个条件吗?

(我只找到了AccountExpirationDateAccountLockoutDate)

  • 用户密码将在不久的将来到期。
  • 用户密码已过期
  • 检查用户密码是否过期
  • 用户帐户过期(帐户,没有密码)
  • 过期用户帐户(帐户,没有密码)
  • 用户帐户未过期
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-07 16:54:39

很抱歉回复得太晚了。我找到了这两个链接的解决方案,它描述了所有的信息。就像它只需要与上面的代码结合一样。

检索域密码策略中“最小密码长度”的值

德里克之家-密码过期电子邮件实用程序

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14408079

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档