Can i use the same run as account for different azure automation accounts?

Viewed 140

I have created a Run As Account for an Azure automation account. Is it possible to use the same Run As Account in a different automation account by creating a new automation connection with the same service principal?

I have tried to create a new automation connection in a different automation account with the same service principal but in the runbook, i get

No certificate was found in the certificate store with thumbprint xxxxxxxxxxxxxxxxxxxx

error.

Any idea?

1 Answers

Let's say the old automation account is account 1, the new one is account 2.

If you create a Run As Account for account 2, it will create a new service principal. If you want to use the service principal of the Run As Account in account 1, you could simply add a new Connection in account 2 like below.

enter image description here

Fix the values with the ones in Run As Account of account 1.

enter image description here

No certificate was found in the certificate store with thumbprint xxxxxxxxxxxxxxxxxxxx

For this issue, maybe there are some issues with the old certificate, you could click the Renew certificate and try again.

Then in your runnbook, e.g. powershell runbook, you could use the new connection to auth with the same service principal.

$connectionName = "testconn"
try
{
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         

    "Logging in to Azure..."
    Connect-AzAccount `
        -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
    }
}
Related