首页 > 解决方案 > 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

到目前为止我添加的权限......猜测我的方式:

在此处输入图像描述

标签: azurepowershellazure-active-directoryazure-ad-b2bazure-ad-powershell-v2

解决方案


Directory.ReadWrite.AllAzure AD Graph API 没有删除用户的权限。

解决方案

要解决此问题,您需要将服务主体分配给目录角色,例如User administrator/ Global administrator

在已删除的回复下,我看到了您的评论:

您不能将目录角色授予服务主体。它必须是 API 权限。

不,实际上我们可以将目录角色授予服务主体。

导航到Azure Active DirectoryAzure 门户中的 -> Roles and administrators-> 单击User administratorGlobal administrator-> Add assignment-> 按服务主体名称搜索(必须搜索)-> 找到并选择它 -> 单击Select

在此处输入图像描述


推荐阅读