Get-AzRoleAssignment在Azure Runbook中引发Microsoft.Rest.Azure.CloudException

人气:57 发布:2023-01-03 标签: azure exception azure-runbook azure-powershell azure-automation

问题描述

我正在Azure Automation帐户中使用Runbook。在本Runbook中,我使用对订阅具有所有者权限的运行方式帐户。当我执行命令Get-AzRoleAssignment时,我得到:

    Get-AzRoleAssignment : Exception of type 'Microsoft.Rest.Azure.CloudException' was thrown. 
    At line:21 char:16 + $listOfUsers = Get-AzRoleAssignment -verbose + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +
 CategoryInfo : CloseError: (:) [Get-AzRoleAssignment], CloudException + FullyQualifiedErrorId : 
Microsoft.Azure.Commands.Resources.GetAzureRoleAssignmentCommand 
运行方式帐户&p>的服务主体具有以下权限:

您有什么想法吗?

这是授权错误吗?如果是,我应该向SP授予哪些权限?

推荐答案

我也可以在我这边复制您的问题,当您使用一些参数运行命令时,例如使用ObjectIdGet-AzRoleAssignment -ObjectId xxxxx,它将首先调用AAD Graph来验证您租户中的对象。

若要解决此问题,只需将Azure Active Directory Graph的的应用程序权限添加到您的RunAs帐户的AD应用程序。

注意:您在屏幕截图中添加了Directory.Read.All,它将不起作用,必须是应用程序权限,请检查以下步骤。

授予权限后,它运行正常。

14