0

I am just getting started with Azure Automation. I downloaded Backup Azure SQL Databases to Blob storage from the gallery. When I run it I get this error:

Connection AzureRunAsConnection not found.

I searched stack overflow and found this post but the links are broken. It's clearly in this function within the runbook:

function Login() {
    $connectionName = "AzureRunAsConnection"
    try
    {
        $servicePrincipalConnection = Get-AutomationConnection -Name $connectionName         

        Write-Verbose "Logging in to Azure..." -Verbose

        Add-AzureRmAccount `
            -ServicePrincipal `
            -TenantId $servicePrincipalConnection.TenantId `
            -ApplicationId $servicePrincipalConnection.ApplicationId `
            -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint | Out-Null
    }
    catch {
        if (!$servicePrincipalConnection)
        {
            $ErrorMessage = "Connection $connectionName not found."
            throw $ErrorMessage
        } else{
            Write-Error -Message $_.Exception
            throw $_.Exception
        }
    }
}

I assume "AzureRunAsConnection" needs to be changed but to what? Is this something that has to be changed in every runbook downloaded? What do I change it to?

lcj
  • 1,355
  • 16
  • 37

1 Answers1

0

@Icj RunAsAccount is the authentication that is used in managing the resources using Azure Automation. Now, Managed Identity is the recommended way to authenticate the runbooks as Managed Identities would be more secure and is managed by Azure without requiring the certificates to be renewed.

When you try to create new Automation Account, you might have noticed that the option to create a Run As account is no longer available.

To connect to Azure using System Managed Identity, you can use below command.

$AzureContext = (Connect-AzAccount -Identity).context

If you want to use RunAsAccount, I suggest you create RunAsAccount by following the steps mentioned in this document.

Reference articles:

SwathiDhanwada
  • 518
  • 3
  • 9
  • Thanks, @SwathiDhanwada-MSFT. Let me see if I can get this running with the changes. I also heard runbooks were a legacy approach and I should be using logic apps or functions. Is this accurate? – lcj Aug 05 '22 at 11:34
  • Each of the service within azure provides its own benefits and limitations. On how to choose services for automating tasks, you can refer this link (https://learn.microsoft.com/en-us/azure/automation/automation-services) where pros and cons are listed out. – SwathiDhanwada Aug 16 '22 at 06:04