Search code examples
powershellazureazure-automation

Creation of an Azure Automation Connection via PowerShell - error 'account was not found'


I am running the following PowerShell code:

Get-AzureRmAutomationAccount `
    -ResourceGroupName $AUTOMATION_ACCOUNT_RESOURCE_GROUP `
    -Name $AUTOMATION_ACCOUNT_NAME 

New-AzureRmAutomationConnection 
    -ResourceGroupName $AUTOMATION_ACCOUNT_RESOURCE_GROUP `
    -AutomationAccountName $AUTOMATION_ACCOUNT_NAME `
    -Name $ConnectionAssetName `
    -ConnectionTypeName AzureServicePrincipal `
    -ConnectionFieldValues $ConnectionFieldValues 

The Get-AzureRmAutomationAccount displays details of the automation account, but New-AzureRmAutomationConnection (although using exactly the same parameter values) throws the following error:

New-AzureRmAutomationConnection : The Automation account was not found.
At line:2 char:1
+ New-AzureRmAutomationConnection -ResourceGroupName $AUTOMATION_ACCOUN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzureRmAutomationConnection], ArgumentException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Automation.Cmdlet.NewAzureAutomationConnection

Any suggestions what I may be missing are appreciated! :)


Solution

  • The error is misleading, the error you are most likely seeing is related to a bad field. Run the cmdlet with debug to see the value is it failing on. You will have to scroll up a bit to find the exception in the body.

    Ensure you have your cert thumbprint, sub id, tenant, and app id. I just tested with the following and it worked as expected. (replaced my values of course). Hope this helps!

    New-AzureRmAutomationConnection `
        -ResourceGroupName TestAzureAuto `
        -AutomationAccountName TestAzureAuto `
        -Name "MyAsset2" `
        -ConnectionTypeName AzureServicePrincipal `
        -ConnectionFieldValues @{"CertificateThumbprint"="0000000000000000000000000000000000000000";"SubscriptionID"="00000000-0000-0000-0000-000000000000";"ApplicationId" = "00000000-0000-0000-0000-000000000000"; "TenantId" = "00000000-0000-0000-0000-000000000000" }