简体   繁体   English

用于在Active Directory中查询的PrincipalContext

[英]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?:

  • what LDAP is used (version 2 or 3) 使用什么LDAP(版本2或3)
  • how set port on which LDAP is running 如何设置LDAP运行的端口
  • how to work if I need SSL connection? 如果我需要SSL连接怎么工作? (different port, must be special requirements) (不同的端口,必须有特殊要求)

Furthermore, can I do with AdvancedSearchFilter this conditions? 此外,我可以使用AdvancedSearchFilter这个条件吗?
(I found only AccountExpirationDate and AccountLockoutDate ) (我发现只有AccountExpirationDateAccountLockoutDate

  • users password will expire in the near future 用户密码将在不久的将来到期
  • users password has expired 用户密码已过期
  • check if the user's password can expire 检查用户的密码是否过期
  • users account expires (account, no password) 用户帐号到期(帐号,无密码)
  • expired users account (account, no password) 过期的用户帐号(帐号,无密码)
  • user account not expired 用户帐户未过期

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.

相关问题 使用 PrincipalContext 连接到活动目录 - Connect to active directory with PrincipalContext C#Active Directory主体上下文权限 - C# Active Directory Principalcontext Permissions Active Directory PrincipalContext.ValidateCredentials域消除歧义 - Active Directory PrincipalContext.ValidateCredentials domain disambiguation 从Active Directory PrincipalContext获取所有用户 - Getting all users from Active Directory PrincipalContext UserPrincipal.FindByIdentity(PrincipalContext context, string identityValue) 如何查询 Active Directory? - How does UserPrincipal.FindByIdentity(PrincipalContext context, string identityValue) query Active Directory? 在 Active Directory C# 中创建用户的 PrincipalContext 或 DirectoryEntry 哪个更好 - Which is better PrincipalContext or DirectoryEntry for user creation in Active Directory C# Active Directory 跨域 - 使用 PrincipalContext 的组成员 - Active directory cross domain - group members using PrincipalContext 需要在PrincipalContext中的Active Directory中重置密码并使密码过期 - Need to reset and expire a password in Active Directory within a PrincipalContext 为什么不能通过PrincipalContext联系Active Directory服务器? - Why can't the Active Directory server be contacted via PrincipalContext? 如果计算机未加入域,是否可以使用PrincipalContext获取Active Directory信息 - Can PrincipalContext be used to get Active Directory information if computer is not domained joined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM