我想从中做一些简单的报告。在讨论之后,我发现如果我使用.NET FW3.5和更高版本,使用PrincipalContext是合适的。我想了解原理,以及我能用这个新特性做些什么(不像DirectoryEntry)。
代码骨架
// 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:
此外,我能用AdvancedSearchFilter做这个条件吗?
(我只找到了AccountExpirationDate和AccountLockoutDate)
发布于 2013-02-07 16:54:39
很抱歉回复得太晚了。我找到了这两个链接的解决方案,它描述了所有的信息。就像它只需要与上面的代码结合一样。
检索域密码策略中“最小密码长度”的值
德里克之家-密码过期电子邮件实用程序
https://stackoverflow.com/questions/14408079
复制相似问题