Automation Account

Nitin Parmar-Tss consultancy 71 Reputation points
2023-03-15T09:32:00.68+00:00

Hi Team, I have an automation account in one subscription, and auto-start powershell is setup in the runbook on the same subscription virtual machine. My question is that I have another virtual machine that is in a different subscription, so do I need to create another automation account to set up the start process for this virtual machine? I have tried with existing automation, but unfortunately, it does not work for different subscriptions.

So,what is solution for that?

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,132 questions
Azure ISV (Independent Software Vendors) and Startups
Azure ISV (Independent Software Vendors) and Startups
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.ISV (Independent Software Vendors) and Startups: A Microsoft program that helps customers adopt Microsoft Cloud solutions and drive user adoption.
89 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 17,726 Reputation points
    2023-03-15T12:01:39.4433333+00:00

    @Nitin Parmar-Tss consultancy Welcome to Microsoft Q&A Platform and thanks for your query. From the information provided, I interpret that using the Runbook(R1) from Subscription(S1), you are trying to start the virtual machine which is in Subscription(S2). Assuming that you are system managed identity, you can use below code at the start of your PowerShell script so that the runbook does not inherit AzContext.

    # Ensures you do not inherit an AzContext in your runbook
    Disable-AzContextAutosave -Scope Process
    # Connect to Azure with system-assigned managed identity
    $AzureContext = (Connect-AzAccount -Identity).context
    # Set and store context
    $AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext
    

    If you are using user managed identity, you need to use below code.

    
    # Ensures you do not inherit an AzContext in your runbook
    Disable-AzContextAutosave -Scope Process
    
    # Connect to Azure with system-assigned managed identity
    $AzureContext = (Connect-AzAccount -Identity -AccountId <ClientId>).context
    
    # set and store context
    $AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription `
        -DefaultProfile $AzureContext
    
    

    Also, make sure you provide appropriate permissions for the managed identity by following document mentioned here. Kindly note that both subscriptions must be same Azure Active Directory tenant.

    0 comments No comments