-1

我正在尝试从 LDAP 获取所有组及其相关的子组和成员。

我正在使用这段代码:

public List<Group> GetGroups()
{
        DirectoryEntry de = new DirectoryEntry("LDAP://someLdap.com");
        DirectorySearcher searcher = new DirectorySearcher(de);
        searcher.Filter = "(&(objectClass=group))";
        searcher.PageSize = 500;

        searcher.PropertiesToLoad.Add("sAMAccountName");
        searcher.PropertiesToLoad.Add("description");
        searcher.PropertiesToLoad.Add("memeber"); 
        searcher.PropertiesToLoad.Add("memeberOf");
        searcher.SearchScope = SearchScope.Subtree;

        List<Group> groups;
        using (SearchResultCollection results = searcher.FindAll())
        {
            int count = 1;
            groups = new List<Group>();

            foreach (SearchResult result in results)
            {
                Group group = new Group();
                if (result == null) continue;
                Console.WriteLine(count++); // just to print 

                group.Name = result.Properties["sAMAccountName"][0].ToString();
                group.Description = result.Properties["description"][0].ToString();
                ResultPropertyValueCollection valueCollection =
                    result.Properties["memeber"];
                foreach (var user in valueCollection)
                {
                    group.Users.Add(user.ToString());
                }

                groups.Add(group);
            }
        }
        return groups;
    }

该代码仅适用于sAMAccountNamedescription

但我无法获得全部membermemberOf价值

有任何想法吗?

4

1 回答 1

1

那是因为您在整个代码和帖子中都拼错了属性名称。

于 2013-01-28T23:31:59.853 回答