我找了用户谁使用GroupPrincipal的AD组的成员。
I am looking up users who are members of an AD group using GroupPrincipal.
GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, "Advisors");
我需要从该查询得到的雇员场,但我相信使用UserPrincipal这仅仅是可能的。
I need to get the EmployeeID field from this lookup but I believe this is only possible using UserPrincipal.
var members = group.Members.Select(x => new DomainContext() { EmployeeID = x.EmployeeId, FullName = x.DisplayName }).ToList();
有谁知道的办法解决这?
Does anyone know of a way round this?
您已经除非你使用底层的DirectoryEntry / DirectorySearcher从类使用UserPrincipal。
You have to use UserPrincipal unless you're using the underlying DirectoryEntry/DirectorySearcher classes.
您应该使用.GetMembers代替.Members(),那么你可以做的东西,如:
You should use .GetMembers() instead of .Members then you can do stuff like:
var userMembers = group.GetMembers().OfType<UserPrincipal>();
foreach( var member in userMembers) {
string empid = member.EmployeeId; //do something with the EmployeeId
}