Get-AzRoleAssignment 在 Azure Runbook 中抛出 Microsoft.Rest.Azure.CloudException
Get-AzRoleAssignment throws Microsoft.Rest.Azure.CloudException in Azure Runbook
我在 Azure 自动化帐户中使用 运行book。在这本 运行 书中,我使用“运行 作为帐户”,它拥有订阅的所有者权限。当我执行命令 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
“运行 作为帐户”的服务主体具有以下权限:
你有什么想法吗?
是否授权错误?如果是这样,我应该给 SP 哪些权限?
我也可以在我这边重现你的问题,当你 运行 命令带有一些参数时,例如使用 ObjectId
、Get-AzRoleAssignment -ObjectId xxxxx
,它将首先调用 AAD Graph 来验证您租户中的对象。
要解决这个问题,只需将Azure Active Directory Graph
的应用程序权限 Directory.Read.All
添加到您的AD App RunAs 帐户。
注意:在您的屏幕截图中,您添加了委派权限Directory.Read.All
, 不行, 必须申请权限, 看下面步骤.
授予权限后,一切正常
我在 Azure 自动化帐户中使用 运行book。在这本 运行 书中,我使用“运行 作为帐户”,它拥有订阅的所有者权限。当我执行命令 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
“运行 作为帐户”的服务主体具有以下权限:
你有什么想法吗?
是否授权错误?如果是这样,我应该给 SP 哪些权限?
我也可以在我这边重现你的问题,当你 运行 命令带有一些参数时,例如使用 ObjectId
、Get-AzRoleAssignment -ObjectId xxxxx
,它将首先调用 AAD Graph 来验证您租户中的对象。
要解决这个问题,只需将Azure Active Directory Graph
的应用程序权限 Directory.Read.All
添加到您的AD App RunAs 帐户。
注意:在您的屏幕截图中,您添加了委派权限Directory.Read.All
, 不行, 必须申请权限, 看下面步骤.
授予权限后,一切正常