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

Mohamed Guendouzi 0 Reputation points
2024-03-27T14:36:37.9766667+00:00

Hello,

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
    2024-03-28T02:41:29.4166667+00:00

    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.

    try
    {
        #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