Azure automation - credentials delivered by Get-PSAutomationCredential don't work with Add-AzureAccount?

前端 未结 2 1804
囚心锁ツ
囚心锁ツ 2020-12-22 09:51

I\'m modifying a gallery runbook that copies a live database to a test database on a schedule. It\'s failing at the first hurdle; authenticating and selecting the relevatn a

相关标签:
2条回答
  • 2020-12-22 10:05

    According to your description, it seems that your account is a Microsoft account(such as *@outlook.com, *@hotmail.com). Microsoft does not support non-interactive login. It is also unsafe for you to use your account to login your subscription directly. For a runbook, you could use the following codes to logon.

    $connectionName = "AzureRunAsConnection"
    try
    {
        # Get the connection "AzureRunAsConnection "
        $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         
    
        "Logging in to Azure..."
        Add-AzureRmAccount `
            -ServicePrincipal `
            -TenantId $servicePrincipalConnection.TenantId `
            -ApplicationId $servicePrincipalConnection.ApplicationId `
            -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 
    }
    catch {
        if (!$servicePrincipalConnection)
        {
            $ErrorMessage = "Connection $connectionName not found."
            throw $ErrorMessage
        } else{
            Write-Error -Message $_.Exception
            throw $_.Exception
        }
    }
    

    In above code, you need use connection AzureRunAsConnection, it is created by Azure default, you could use it directly, you could check this connection, it includes your subscription information.

    Also, you could create a new connection, please refer to this link.

    0 讨论(0)
  • 2020-12-22 10:27

    Have you tried using the resource manager version off the login cmdlet (Add-AzureRmAccount)?

    0 讨论(0)
提交回复
热议问题