0

I'm unable to get certain fields from user objects such as PasswordNeverExpires. Right now I'm cycling through every property returned by over 2000 users and my conditional breakpoint never breaks once, so I know it's not returning. If I break unconditionally the number of properties returned by this code is always 1. Our sever is Windows 2003 Server. I can get all the information I want from NetEnum commands. I've seen others claim that they can do this and I don't see what's different about my code. When I don't provide any properties to load, it grabs about 30-37 properties. Several of these properties I need and use.

    public void FetchUsers(string domainId, Sql sql)
    {
        var entry = new DirectoryEntry("LDAP://" + DomainControllerAddress, DomainPrefixedUsername, Password,
            AuthenticationType);

        var dSearch = new DirectorySearcher(entry)
        {
            Filter = "(&(objectClass=user)(!(objectclass=computer)))",
            SearchScope = SearchScope.Subtree,
            PageSize = 1000,

        };

        dSearch.PropertiesToLoad.Add("passwordneverexpires");

        var users = dSearch.FindAll();

        foreach (SearchResult ldapUser in users)
        {
            SaveUser(ldapUser, sql, domainId);
        }
    }

    private void SaveUser(SearchResult ldapUser, Sql sql, string domainId)
    {
        if (ldapUser.Properties.PropertyNames == null) return;

        foreach (string propertyName in ldapUser.Properties.PropertyNames)
        {
//I'm breaking here on the condition that propertyName != 'adspath' and it never breaks
            var v = ldapUser.Properties[propertyName];
        }

        return;
}
4

2 回答 2

0

一些事情:

  1. 您拥有的基本过滤器效率非常低。改用这个(&(objectCategory=person)(objectClass=user))
  2. 没有名为 passwordneverexpires 的属性。您需要检查userAccountControl用户掩码中的第 13 位 -有关值列表,请参见http://msdn.microsoft.com/en-us/library/aa772300%28v=vs.85%29.aspx 。
  3. 你永远不会闯入你的循环,因为你告诉客户只请求一个属性。
于 2014-09-03T13:38:13.230 回答
0

您可以使用过滤器,例如: (&(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=65536)) 获取具有帐户​​配置 DONT_EXPIRE_PASSWORD 的所有用户

-吉姆

于 2014-09-04T10:38:28.263 回答