I want to migrate from an existing Run As account to managed identities

Mohamed Guendouzi 0 Reputation points


I would like to change my runbook which starts and stops several machines knowing that I have an exclusion list. I would like to change it for authentication with managed identities.

how do I send my powershell runbook script here?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,111 questions
{count} votes

1 answer

Sort by: Most helpful
  1. tbgangav-MSFT 10,381 Reputation points

    Hi @Mohamed Guendouzi , Yes, you should modify only that part. It's explained in the same document that I have shared earlier i.e., in this section of the document.

    Please follow the document from the start i.e., create managed identity, assign role, migrate run as account to managed identity and use code in the sample scripts section to modify connection part.

    So, your runbook might look something like below if you have created system assigned managed identity.

        #Flag for CSP subs
        $enableClassicVMs = Get-AutomationVariable -Name 'External_EnableClassicVMs'
        "Logging in to Azure..."
        Connect-AzAccount -Identity
    catch {
        Write-Error -Message $_.Exception
        throw $_.Exception
    0 comments No comments