获取异常
system.directoryservices.accountmanagement.principaloperationexception :服务器上没有这样的对象
试图让一个组的所有成员。仅获得一个特定组的例外,能够获得具有相同代码的其他组的成员。
我正在尝试以下代码
public void GetADusers(string groupName, string domainName, string AdUser, string ADPassword, Hashtable SamName, Hashtable DisplayName, Hashtable POR, Hashtable Mail)
{
try
{
string powergroup = System.Configuration.ConfigurationManager.AppSettings["PowerGroup"];
string retrieveGroup = System.Configuration.ConfigurationManager.AppSettings["RetrieveGroup"];
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domainName, AdUser, ADPassword);
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, groupName);
if (grp != null)
{
foreach (Principal p in grp.GetMembers(false))
{
if (!SamName.Contains(p.SamAccountName))
{
SamName.Add(p.SamAccountName, p.SamAccountName);
DisplayName.Add(p.SamAccountName, p.DisplayName);
Mail.Add(p.SamAccountName, p.UserPrincipalName);
POR.Add(p.SamAccountName, false);
}
if ((groupName == powergroup || groupName == retrieveGroup) && SamName.Contains(p.SamAccountName))
POR[p.SamAccountName] = true;
}
grp.Dispose();
ctx.Dispose();
}
}
catch (Exception ex)
{
log.Error("usersByFilter: ", ex);
throw ex;
}
}
该组包含600名成员,部分成员是跨域用户