How to call child runbooks from parent runbook without waiting for child runbook completion and move to next line

Ponkam, Sumanth (Cognizant) 50 Reputation points
2024-05-21T13:25:53.5333333+00:00

I have runbook A as parent and B, C are Child. I want to create a runbook A that should invoke B, C and continue executing the next line in the parent runbook. parent should not wait for child runbooks to be completed. can we have some sample code

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

1 answer

Sort by: Most helpful
  1. AnuragSingh-MSFT 21,236 Reputation points
    2024-05-21T15:00:04.95+00:00

    @Ponkam, Sumanth (Cognizant), to ensure that you do not wait for the child runbook to complete before executing the next line, the Start-AzAutomationRunbook without -wait parameter.

    For details, see Start a child runbook by using a cmdlet.

    The sample runbook snippet is as below:

    # Ensure that the runbook does not inherit an AzContext 
    
    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  
    
    $params = @{"VMName"="MyVM";"RepeatCount"=2;"Restart"=$true}  
    
    Start-AzAutomationRunbook -AutomationAccountName 'MyAutomationAccount' -Name 'Test-ChildRunbook' -ResourceGroupName 'LabRG' -DefaultProfile $AzureContext -Parameters $params
    
    <continue PowerShell code further>
    

    Hope this helps.

    If the answer did not help, please add more context/follow-up question for it. Else, if the answer helped, please click Accept answer so that it can help others in the community looking for help on similar topics.