代码之家  ›  专栏  ›  技术社区  ›  Caius Jard

Azure automation-Get-PSAutomationCredential提供的凭据与Add-AzureAccount不兼容?

  •  0
  • Caius Jard  · 技术社区  · 7 年前

    我正在修改一个库runbook,它按计划将实时数据库复制到测试数据库。它在第一个栏就失败了;验证和选择Relevant azure订阅

    $Cred = Get-AutomationPSCredential -Name 'automationCredential'
    
    Write-Output "UN: $($Cred.Username)"
    
    Add-AzureAccount -Credential $Cred
    

    我使用门户凭据刀片创建了一个名为“automationCredential”的凭据。对于用户名和密码,我提供了登录azure门户时使用的用户名/密码。注意:这不是学校/工作microsoft帐户,而是个人帐户

    我可以告诉你,获取PSAutomationCredential的呼叫正在进行中,因为 Write-Ouput

    Add-AzureAccount : unknown_user_type: Unknown User Type At
    Set-DailyDatabaseRestore:22 char:22 CategoryInfo          :
    CloseError: (:) [Add-AzureAccount], AadAuthenticationFailedException
    FullyQualifiedErrorId :
    Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount
    

    有没有关于如何获得工作凭证的建议?

    2 回复  |  直到 7 年前
        1
  •  1
  •   Shui shengbao    7 年前

    根据您的描述,您的帐户似乎是Microsoft帐户(例如*@outlook.com,*@hotmail.com)。Microsoft不支持非交互式登录。使用您的帐户直接登录您的订阅也是不安全的。对于runbook,您可以使用以下代码登录。

    $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
        }
    }
    

    在上面的代码中,您需要使用连接 AzureRunAsConnection ,它是由Azure默认创建的,您可以直接使用它,您可以检查此连接,它包括您的订阅信息。 enter image description here

    此外,您可以创建一个新连接,请参阅 link

        2
  •  1
  •   Jenny Hunter    7 年前

    您是否尝试过在登录cmdlet(Add-AzureRmAccount)之外使用资源管理器版本?