更新时间:2023-02-21 10:37:09
With 3.5 and System.DirectoryServices.AccountManagement 这更简洁一些:
With 3.5 and System.DirectoryServices.AccountManagement this is a bit cleaner:
public List<string> GetGroupNames(string userName)
{
var pc = new PrincipalContext(ContextType.Domain);
var src = UserPrincipal.FindByIdentity(pc, userName).GetGroups(pc);
var result = new List<string>();
src.ToList().ForEach(sr => result.Add(sr.SamAccountName));
return result;
}