首页 > 解决方案 > Azure 自动化 - 无法获取 AzRoleAssignement

问题描述

为了使某些流程自动化,我正在使用具有 RunAsAccount 所有者权限的Azure 自动化。

$connection = Get-AutomationConnection -Name AzureRunAsConnection

while(!($connectionResult) -And ($logonAttempt -le 10))
{
    $LogonAttempt++
    # Logging in to Azure...
    $connectionResult =    Connect-AzAccount `
                               -ServicePrincipal `
                               -Tenant $connection.TenantID `
                               -ApplicationId $connection.ApplicationID `
                               -CertificateThumbprint $connection.CertificateThumbprint

    Start-Sleep -Seconds 30
    Write-Output $connectionResult
}

Get-AzRoleAssignment -ResourceGroupName $USERRGNAME -SignInName $USEREMAIL -verbos

每次执行脚本时都会引发错误

Get-AzRoleAssignment: Cannot find principal using the specified options

有什么想法可以解决这个问题吗?

标签: azureazure-powershellazure-automationazure-rbac

解决方案


可能您需要为RunAsAccount提供 Azure AD Graph 的应用程序权限Directory.Read.All(不是 Microsoft Graph,不是委派权限)。默认情况下,RunAsAccount没有 Azure AD 权限。

在此处输入图像描述

您可以阅读乔伊的答案以获取更多详细信息。


推荐阅读