gpt4 book ai didi

powershell - 通过 Graph 更新 AzureAD/O365 UPN

转载 作者:行者123 更新时间:2023-12-03 03:12:29 25 4
gpt4 key购买 nike

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

$UPN="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2c595f495e6c41555849424d425802494859" rel="noreferrer noopener nofollow">[email protected]</a>"
$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/changing-upn-for-office-365-account-between-two-sso-domains/ 中描述的问题),我会收到内部服务器错误 (500):

$UPN="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="98edebfdead8f5e1ecfdf6f9f6ecb6fdfced" rel="noreferrer noopener nofollow">[email protected]</a>"
$Body=@{userPrincipalName="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="394c4a5c4b794d5c5758574d17565754505a4b564a565f4d175a5654" rel="noreferrer noopener nofollow">[email protected]</a>"} | 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 可以像其他属性一样更新(例如 c.v. http://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/user_update )。我想知道是否因为 UPN 是 key ,也许这会使更新不起作用?我也不认为这是权限问题,那些通常会抛出“没有足够的权限来完成操作”。这不是我所看到的。

谢谢!

UPDATE1:这是我今天早上重新尝试时可以从 Error 对象中获取的所有内容:

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

最佳答案

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

关于powershell - 通过 Graph 更新 AzureAD/O365 UPN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35232113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com