Dynamic CRM 365 启用用户systemuser、修改用户systemuser的时候报错:The selected object could not be found. Verify that the object exists in both the database and Active Directory.

现象:

1.启用用户的时候报错:The selected object could not be found. Verify that the object exists in both the database and Active Directory.

2.更新systemuser的时候报错:System.DirectoryServices.DirectoryServicesCOMException (0x80072030): There is no such object on the server.(服务器上没有此类对象。)

Entity systemuser = new Entity("systemuser");
systemuser["isdisabled"] = false;
systemuser["domainname"] = "xxxxx";//域登录名
OrganizationServiceAdmin.Update(systemuser);

根本原因:

该错误清楚地告诉我,Active Directory上的用户设置肯定存在问题。在进一步深入研究之后,我发现这个问题发生的原因为:

  1. 用户已添加到AD
  2. 用户已添加到CRM
  3. 用户在CRM中被禁用
  4. 用户已从AD中删除
  5. 用户再次在AD中创建

结论:

现在,只要您创建用户(适用于AD身份验证),它就会在CRM中存储AD帐户的对象GUID,其数据库列为  systemuser 表中的ActiveDirectoryGuid字段

 

所以现在当你尝试再次启用用户时 - CRM从AD获取此对象GUID,但是找不到,因此会给你这个错误。

解决方案(两种):

  1. 从Active Directory获取新GUID并更新CRM数据库systemuserbase表中的ActiveDirectoryGuid列.
  2. 在CRM中为此用户创建一个新的用户帐户使用;
 

重点介绍第一种解决方案(其实就是"CRM域用户误删恢复")

从2011版本开始CRM中不单记录了用户的域账号,而且还记录了域用户的GUID和SID,所以要恢复域用户参考以下sql步骤(在Dynamics 365测试通过)

use [Test_MSCRM]--CRM组织数据库

declare @orgName nvarchar(200)='Test' --CRM组织名称
declare @DomainName nvarchar(1024)='Domain est' ----CRM中原用户的登录域名
declare @adguid uniqueidentifier='C143E7B6-87FB-4646-A9B1-7DAD1CD7B022' --新创建的ad用户在ad里的guid ,如何查看guid参考以下
declare @authInfo nvarchar(255)='W:' + 'S-1-5-21-1982881794-697207762-1046364067-1122' --新创建的ad用户在ad里的sid,如何查看sid参考以下

declare @crmUserid uniqueidentifier

--获取CRM中原用户的systemuserid
select @crmUserid=[SystemUserId]
from [dbo].[SystemUserBase]
where [DomainName]=@DomainName

update [dbo].[SystemUserBase] --将新创建的ad用户ad里的guid更新到此表
set [ActiveDirectoryGuid]=@adguid
where [SystemUserId]=@crmUserid

use [MSCRM_CONFIG]

declare @configUserid uniqueidentifier
declare @orgid uniqueidentifier

--获取组织id
select @orgid=[Id]
from [dbo].[Organization]
where [UniqueName]=@orgName

--获取config中用户id
select @configUserid=[UserId]
from [dbo].[SystemUserOrganizations]
where [OrganizationId]=@orgid
and [CrmUserId]=@crmUserid

update [dbo].[SystemUserAuthentication] --将新创建的ad用户ad里的sid更新到此表
set [AuthInfo]=@authInfo
where [UserId]=@configUserid 

go

如何查看域用户的SID和GUID?

在我们AD服务器,PowerShell里面输入:Get-ADUser -Filter 'Name -like "*crmadmin*"'  ;就可以实现查看某个用户的ObjectGuid和SID

原文地址:https://www.cnblogs.com/parkerchen/p/13397370.html