[英]PrincipalContext for query in Active Directory
I want to make a few simple reports from Active Directory. 我想从Active Directory中制作一些简单的报告。 Following discussions, etc. I found that if I use .NET FW 3.5 and up, it is appropriate to use PrincipalContext
. 经过讨论等,我发现如果我使用.NET FW 3.5及更高版本,则使用PrincipalContext
是合适的。 I would like to understand principles and what I can do with this new feature (unlike DirectoryEntry
). 我想了解原理以及我可以用这个新功能做什么(与DirectoryEntry
不同)。
Code skeleton 代码骨架
// 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
}
}
It is possible by code up add this properties for login to LDAP?: 可以通过代码添加此属性来登录LDAP?:
Furthermore, can I do with AdvancedSearchFilter
this conditions? 此外,我可以使用AdvancedSearchFilter
这个条件吗?
(I found only AccountExpirationDate
and AccountLockoutDate
) (我发现只有AccountExpirationDate
和AccountLockoutDate
)
sorry for the late reply. 这么晚才回复很抱歉。 The solution I found these two links, which describes all the information. 解决方案我找到了这两个链接,它描述了所有信息。 Just as it only needs to combine with the code above. 就像它只需要与上面的代码结合一样。
retrieve the value of "Minimum Password Length" in domain password policy 检索域密码策略中“最小密码长度”的值
House of Derek - Password expiration email utility House of Derek - 密码过期电子邮件实用程序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.