azure - Remove-AzureADUser 需要哪些 API 权限?
问题描述
我需要使用 powershell 删除 AAD 来宾用户 - 脚本使用与已注册应用程序对应的证书凭据进行身份验证。注册的应用需要哪些 API 权限?
Connect-AzureAD -TenantId $TenantId -ApplicationId $ApplicationId -CertificateThumbprint $CertificateThumbprint
Remove-AzureADUser -ObjectId $guestKey
结果错误:
Remove-AzureADUser : Error occurred while executing RemoveUser
Code: Authorization_RequestDenied
Message: Insufficient privileges to complete the operation.
RequestId: fa05248f-60be-48fa-8ef5-7a381f6e61dd
DateTimeStamp: Thu, 13 Jun 2019 18:15:52 GMT
HttpStatusCode: Forbidden
HttpStatusDescription: Forbidden
HttpResponseStatus: Completed
At C:\Scripts\disable-inactive-guests.ps1:116 char:9
+ Remove-AzureADUser -ObjectId $guestKey
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Remove-AzureADUser], ApiException
+ FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.RemoveUser
到目前为止我添加的权限......猜测我的方式:
解决方案
Directory.ReadWrite.All
Azure AD Graph API 没有删除用户的权限。
解决方案:
要解决此问题,您需要将服务主体分配给目录角色,例如User administrator
/ Global administrator
。
在已删除的回复下,我看到了您的评论:
您不能将目录角色授予服务主体。它必须是 API 权限。
不,实际上我们可以将目录角色授予服务主体。
导航到Azure Active Directory
Azure 门户中的 -> Roles and administrators
-> 单击User administrator
或Global administrator
-> Add assignment
-> 按服务主体名称搜索(必须搜索)-> 找到并选择它 -> 单击Select
。
推荐阅读
- html - 图像不会填充按钮大小,无论图像大小如何,它都会有奇怪的边距
- azure - 从 azure Data factory 到 Databricks 的链接服务:如何参数化?
- python - Tox 不尊重自定义环境中定义的 envlist
- javascript - ASP.NET 核心 MVC 弹出模式,其中包含来自视图的模型数据
- python - 条件满足时填写nan值
- javascript - 如何在 Chartjs 的边框处添加渐变色
- keras - 带有 VGG16 模型拟合误差的迁移学习
- wordpress - 如何插入媒体库中的图像并将其设置为前端帖子表单中的特色图像
- python - 拉出分类行并应用于所有后续行,直到找到新类别
- r - 为什么航空旅客数据集的暗淡在 R 中为空?