Powershell Azure : The term 'Get-AutomationConnection' is not recognized as the name of a cmdlet, function, script file, or operable program

11,722

If you want to connect to an Azure Run As connection from Windows PowerShell, you should use New-AzureRmAutomationConnection.

$ConnectionAssetName = "AzureRunAsConnection"
$ConnectionFieldValues = @{"ApplicationId" = $Application.ApplicationId; "TenantId" = $TenantID.TenantId; "CertificateThumbprint" = $Cert.Thumbprint; "SubscriptionId" = $SubscriptionId}
New-AzureRmAutomationConnection -ResourceGroupName $ResourceGroup -AutomationAccountName $AutomationAccountName -Name $ConnectionAssetName -ConnectionTypeName AzureServicePrincipal -ConnectionFieldValues $ConnectionFieldValues 

You are able to use the script to create the connection asset because when you create your Automation account, it automatically includes several global modules by default along with the connection type AzurServicePrincipal to create the AzureRunAsConnection connection asset.

Get-AutomationConnection runs in Azure runbook internally.

Please refer to connection assets in Azure Automation.

Share:
11,722
Peter PitLock
Author by

Peter PitLock

Updated on June 05, 2022

Comments

  • Peter PitLock
    Peter PitLock almost 2 years

    I am trying to connect to an Azure Run As connection, as part of a Powershell script that does a backup of a database.

    This script attempts to call Get-AutomationConnection

    As seen in the screenshot, Get-Module does return that Azure / Azure.Storage and AzureRM shows.

    What module should I import in addition for this to work?

    enter image description here

  • Gill-Bates
    Gill-Bates almost 3 years
    AzureAutomationAuthoringToolkit does not support Powershell 7!
  • woter324
    woter324 almost 3 years
    This answer is over 4 years old! Things have progressed somewhat. AAATK was an "extension" for PowerShell ISE. ISE doesn't work with PS 6.x or 7.x. AAATK is no longer maintained as there are a bunch of other tools that have replaced it.