我已经敲了好几个小时,试图弄清楚为什么这不起作用。我找到了一个从 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 中的所有用户。感谢您的帮助!