1
要獲取Active Directory中的所有組,我已使用C#編寫此代碼。它的工作原理非常清楚,因爲我不需要通過任何服務器名,OU,DC等活動目錄獲取除特殊組以外的所有組
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,遠程登錄太多組客戶等。
我只需要管理員,訪客和其他用戶創建組等組。我已閱讀有關這些是特殊組等等等
在這方面的任何幫助,高度讚賞。