1

我正在尝试通过 MS Graph 利用 Powershell 中的 .Net ADAL 库来更新联合域中 Azure AD 用户(使用 Azure AD Connect 加载)的 UPN。我有理由确定我已在 Azure 和 PS 中正确配置了所有内容,因为如果我发出更新 usageLocation 属性的命令,它会起作用(为简洁起见已剪辑):

$UPN="user@mytenant.edu"
$Body=@{UsageLocation="JP"} | ConvertTo-JSON
$Result=Invoke-RestMethod -Method PATCH -Uri "https://graph.microsoft.com/v1.0/users/${UPN}" -Headers @{Authorization=$authenticationResult.CreateAuthorizationHeader()} -ContentType "application/json" -Body $Body
$user=Invoke-RestMethod -Method GET -Uri "https://graph.microsoft.com/v1.0/users/${UPN}?`$select=usageLocation" -Headers @{Authorization=$authenticationResult.CreateAuthorizationHeader()} -ContentType "application/json"
$user.usageLocation

JP

但是,如果我尝试将 UPN 更新到非联合域(所以我不会与http://blogs.perficient.com/microsoft/2013/03/changeing-upn-for-office中描述的问题发生冲突-365-account-between-two-sso-domains/),我得到一个内部服务器错误(500):

$UPN="user@mytenant.edu"
$Body=@{userPrincipalName="user@tenant.onmicrosoft.com"} | ConvertTo-JSON
$Result=Invoke-RestMethod -Method PATCH -Uri "https://graph.microsoft.com/v1.0/users/${UPN}" -Headers @{Authorization=$authenticationResult.CreateAuthorizationHeader()} -ContentType "application/json" -Body $Body

Invoke-RestMethod : The remote server returned an error: (500) Internal Server Error.

我尝试了许多不同的变体,包括检索 Azure AD GUID 并在 PATCH 命令中使用它而不是 UPN,以及使用较旧的 Azure AD Graph(返回相同的 500 错误)。我可以使用 O365 Powershell 命令进行更改:

Set-MsolUserPrincipalName -UserPrincipalName $UPN -NewUserPrincipalName $newUPN

但我似乎无法通过 MS Graph 使其工作。graph 的文档暗示 UPN 可以像其他属性一样更新(例如,cv http://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/user_update)。我想知道是否因为 UPN 是一个密钥,也许这会使更新不起作用?我也不认为这是权限问题,通常会抛出“权限不足,无法完成操作”。这不是我所看到的。

谢谢!

UPDATE1:这是我今天早上重新尝试时可以从错误对象中找出的所有内容:

{
  "error": {
    "code": "Service_InternalServerError",
    "message": "Encountered an internal server error.",
    "innerError": {
      "request-id": "cbb08d3c-1143-4d0b-8722-5230b00bd00f",
      "date": "2016-02-15T16:48:15"
    }
  }
}
4

1 回答 1

1

我查看了跟踪,我将在我们这边为 500 错误提交一个错误(我们当然可以在这里做得更好)。根据跟踪,如果您通过将用户从联合域重命名为云管理域来更新用户,则必须在请求中提供/设置密码(使用 passwordProfile 复杂类型)。这就是为什么根据日志请求失败的原因。如果这能解决您的问题,请告诉我们。

于 2016-02-16T18:06:22.703 回答