我想从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?:
此外,我可以使用AdvancedSearchFilter
这个条件吗?
(我发现只有AccountExpirationDate
和AccountLockoutDate
)
答案 0 :(得分:0)
retrieve the value of "Minimum Password Length" in domain password policy