In this blog post, we will show how to connect to Azure from an Azure Automation PowerShell runbook with managed identity.
Managed Identities are new service account accounts in Azure Automation that replace the Run As Account service accounts.
With Azure Run As Account being retired on the 30th of September, PowerShell scripts that use Run As Account will need to be changed to use Managed Identities.
The following PowerShell code will configure PowerShell runbooks to connect to Azure using a Managed Identity account.
# Disable inherit of AzContext in the runbook Disable-AzContextAutosave -Scope Process # Connect to Azure with system-assigned managed identity $AzureContext = (Connect-AzAccount -Identity).context get-AzVM
The above code will connect to Azure and allow you to run your scripts without any issues.