我需要查询AD以检索域及其子域中的组。当我运行以下代码时,我得到的只是当前的域组,而不是来自子域的组(例如:mydomain.com和child.mydomain.com)。你对我失踪了吗?
using(var filter = new GroupPrincipal(new PrincipalContext(ContextType.Domain)))
{
filter.IsSecurityGroup = true;
filter.GroupScope = GroupScope.Global;
using(var searcher = new PrincipalSearcher(filter)
using(var results = searcher.FindAll())
{
//results contains the groups in mydomain.com only
}
}
(更新代码以更好地描述所做的调用)