【问题标题】:Getting users from an Active Directory group从 Active Directory 组中获取用户
【发布时间】:2011-07-06 22:26:30
【问题描述】:

我已经敲了好几个小时想弄清楚为什么这不起作用。我找到了一个从 AD 组获取用户列表的示例,但我无法让它工作。这是我一直在尝试做的事情:

DirectoryEntry de = new DirectoryEntry("LDAP://DC=" + domain + ",DC=com");

DirectorySearcher ds = new DirectorySearcher(de);//, "(objectClass=person)");

ds.Filter = "(&(objectCategory=person)(objectclass=user)(memberOf=CN=!CityNameGroup))"; 

ds.PropertiesToLoad.Add("givenname");
ds.PropertiesToLoad.Add("samaccountname");
ds.PropertiesToLoad.Add("sn");
ds.PropertiesToLoad.Add("useraccountcontrol");

foreach (SearchResult sr in ds.FindAll())
{//stuff goes here}

ds.FindAll 总是使用此过滤器返回 0 个结果。我可以做更简单的过滤器来返回结果,但我从来没有从上面的过滤器中得到任何东西。我只想要 !CityNameGroup 中的所有用户。感谢您的帮助!

【问题讨论】:

    标签: c# active-directory directoryentry


    【解决方案1】:

    如果 .NET 3.5 是一个选项,请不要胡思乱想,看看这里:

    Everything in Active Directory via C#.NET 3.5 (Using System.DirectoryServices.AccountManagement)

    说真的,.NET 3.5 中的 AD 处理是另一个世界。它会改变一切。当然是为了更好。

    更新

    此外,这里有一个现成的答案 (Active Directory User Group Memberships GroupPrincipal)。我将有礼貌的不复制它。 :)

    它使用 .NET 3.5,顺便说一句。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-14
      • 1970-01-01
      相关资源
      最近更新 更多