【问题标题】:Active Directory Group Members IssueActive Directory 组成员问题
【发布时间】:2013-05-02 21:20:58
【问题描述】:

我正在使用以下代码从组中获取成员。

private static List<string> GetGroupMembers(string groupName)
{
  Tracer.LogEntrace(groupName);

  List<string> retVal = new List<string>();

  GroupPrincipal groupPrincipal = 
    GroupPrincipal.FindByIdentity(
      new PrincipalContext(ContextType.Domain), 
      IdentityType.SamAccountName,
      groupName);

  PrincipalSearchResult<Principal> principleSearchResult = 
    groupPrincipal.GetMembers(true);

  if (principleSearchResult != null)
  {
     try
     {
        foreach (Principal item in principleSearchResult)
           retVal.Add(item.DistinguishedName);
     }
     catch (Exception ex)
     {
        Tracer.Log(ex.Message);
     }
  }
  else
  {
    //Do Nothing
  }

  Tracer.LogExit(retVal.Count);

  return retVal;

}

它适用于所有组,但当它进入用户组时,我收到以下错误

“发生错误 (87) 枚举组。该组的 无法解析 SID。”

【问题讨论】:

  • 可能您的意思是“域用户”,而不是“用户”

标签: c# active-directory


【解决方案1】:

Users 在 Active Directory 中不是组 - 它是一个容器。这就是为什么你不能像一个组一样枚举它 - 你必须像一个 OU(组织单位)一样枚举它。

类似:

// bind to the "Users" container
DirectoryEntry deUsers = new DirectoryEntry("LDAP://CN=Users,DC=yourcompany,DC=com");

// enumerate over its child entries
foreach(DirectoryEntry deChild in deUsers.Children)
{
   // do whatever you need to do to those entries
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多