Active Directory의 모든 그룹을 얻으려면이 코드를 C#으로 작성하십시오. 내가 등 모든 서버 이름, OU, DC를 통과 할 필요가없는 것처럼 완벽하게 잘 작동Active Directory 특수 그룹을 제외한 모든 그룹을 가져옵니다.
UserPrincipal current_user = UserPrincipal.Current;
PrincipalContext current_context = current_user.Context;
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
GroupPrincipal qbeUser = new GroupPrincipal(ctx);
Principal userOrGroup = qbeUser as Principal;
userOrGroup.Name = "*";
PrincipalSearcher searcher = new PrincipalSearcher(userOrGroup);
List<string> AllGroups = new List<string>();
// enumerate the results - you need to check what kind of principal you get back
foreach (Principal found in searcher.FindAll())
{
// is it a UserPrincipal - do what you need to do with that...
if (found is UserPrincipal)
{
// ......
}
else if (found is GroupPrincipal)
{
AllGroups.Add(found.Name);
//GroupPrincipal gp = found as GroupPrincipal;
//var data = gp.GetMembers();
// if it's a group - do whatever you need to do with a group....
}
}
//return AllGroups;
문제는 내가
PerformanceLogUsers, SchemaAdmins, HelpServiceGroups, 텔넷과 같은 필요가없는 너무 많은 그룹을 나열이다 클라이언트 등등.
관리자, 손님 및 다른 사용자가 만든 그룹과 같은 그룹 만 필요합니다. 나는 이것들에 대해 특별한 단체와 기타 등등을 읽었습니다.
이와 관련하여 도움을 주신 모든 분들께 감사드립니다.