How can I retrieve output from Azure PowerShell child Runbook (7.2) started by 'Start-AutomationRunbook' from within parent Runbook (also 7.2)?

GH-0057 20 Reputation points

Title says it all, I guess.

I am trying to modularize my runbooks and all I want to do is start child RBs using the internal Automation module 'Start-AutomationRunbook' AND get back the result.

This is the sample code I am testing with:

Parent RB:

$result = Start-AutomationRunbook -Name ChildRB
Write-Output $result

Child RB:

$hello = 'Hello world!'
Write-Output $hello

However, instead of storing 'Hello world!' in $result the Job ID is sent to the console.

I have also been trying to use


However, that returns GUID, status etc. but again not 'Hello, world!'. Tried to use the '-OutputJobsTransitionedToRunning' parameter as well, but that didn't do the trick either.

Unfortunately there is no real documentation about the internal Cmdlets for Azure Runbooks.

Any help is much appreciated.

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

Accepted answer
  1. AnuragSingh-MSFT 17,481 Reputation points

    Gordon Hesper, thank you for posting this question on Microsoft Q&A.

    In order to get the Job output from the child runbook, use Get-AzAutomationJobOutput cmdlet from the Az.Automation module. Following is a sample script to start a child runbook, wait for it to complete and then get the output back.

    #Using Managed Identity for Authentication - START
    # 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
    #Using Managed Identity for Authentication -END
    $result = Start-AutomationRunbook -Name ChildRB
    #wait for the job to complete else you may get empty result which creates confusion
    Wait-AutomationJob -Id $result
    #get the output from child runbook.
    $out = Get-AzAutomationJobOutput $result -ResourceGroupName "new-autoAcc" -AutomationAccountName "autoacc" -Stream "Any"
    write-output $out.Summary

    Note that "get-AzAutomationJobOutput" is not an internal automation cmdlet (hence the name contains "Az"). The only internal cmdlets as available are here -

    Hope this helps.

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

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful