PrincipalContext用于在Active Directory中查询
本文关键字:查询 Directory Active 用于 PrincipalContext | 更新日期: 2023-09-27 17:54:49
我想从Active Directory做一些简单的报告。随后的讨论等。我发现,如果我使用。net FW 3.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?:
- 使用什么LDAP(版本2或3)
- 如何设置LDAP运行的端口
- 如果我需要SSL连接,如何工作?(不同端口,必须有特殊要求)
此外,我可以用AdvancedSearchFilter
做这个条件吗?
(我只发现AccountExpirationDate
和AccountLockoutDate
)
- 用户密码即将过期
- 用户密码已过期
- 检查用户的密码是否可以过期
- 用户账号过期(账号,无密码)
- 过期用户账号(账号,无密码)
- 用户帐号未过期
很抱歉回复晚了。我找到的解决方案是这两个链接,它描述了所有的信息。就像它只需要与上面的代码组合一样。
检索域密码策略
中"最小密码长度"的值House of Derek -密码过期电子邮件工具