在尝试解析跨存储引用时,无法解析目标主体的SID.错误代码为1788



我看到了一些类似的文章,但这对解决问题没有帮助。

这是我正在使用的代码片段:

private void GetUsersFromGroup(
PrincipalContext principalContext,
string groupName,
bool isAdminGroup,
IList<User> users,
HashSet<string> userIds)
{
log.Info($"Attempting to find {groupName} group");
GroupPrincipal group = GroupPrincipal.FindByIdentity(principalContext, groupName);
log.Info($"Successfully found {groupName} group");
log.Info($"Attempting to read users from group {group.DistinguishedName}");
var addedUserIds = new List<string>();
foreach (var userPrincipal in group.Members.OfType<UserPrincipal>())
{
if ((userPrincipal.Enabled ?? false) && !userIds.Contains(userPrincipal.UserPrincipalName))
{
users.Add(new User(userPrincipal.UserPrincipalName, userPrincipal.Sid.Value, userPrincipal.DisplayName, userPrincipal.EmailAddress, isAdminGroup));
userIds.Add(userPrincipal.UserPrincipalName.ToLower());
addedUserIds.Add(userPrincipal.UserPrincipalName);
}
}
log.Info($"Successfully read users from group {group.DistinguishedName}. Users read: {string.Join(", ", addedUserIds)}");      
}

错误详细信息

System.DirectoryServices.AccountManagement.PrincipalOperationException:尝试解析跨存储引用时,无法解析目标主体的SID。错误代码为1788。位于System.DirectoryServices.AccountManagement.ADStoreCtx.RResolveCrossStoreRefToPrincipal(对象o(位于System.DirectoryServices.AccountManagement.ADUtils.DirectoryEntryAsPrincipal(DirectoryEntry de,ADStoreCtxstoreCtx(位于System.DirectoryServices.AccountManagement.ADDNLinkedAttrSet.get_CurrentAsPrincipal((位于System.DirectoryServices.AccountManagement.PPrincipalCollectionEnumerator.MoveNext((位于System.Linq.Enumerable.d_95`1.MoveNext((

请告知。

谢谢。

该组可能包含一个来自另一个已不存在的域的帐户。

当组包含来自外部受信任域(不在同一AD林中(的用户时,它会存储一个"外部安全主体"对象,该对象包含该对象的SID。该帐户所在的域实际上不知道该帐户已添加到另一个域上的组中。因此,如果该帐户被删除,则该组不会自动更新。

当您查看Members集合时,它会尝试查找帐户并给您一个UserPrincipal对象,但它不能,因为该帐户已不存在。

最新更新