Question

Gert Humphris ZA on Wed, 23 Aug 2017 20:04:25


Hi Guys 

I've been struggling to get Variables out of a child Runbook in Azure automation. 

I can pass variables in but for some reason I cannot get them out in a variable. 

------------------Parent---------------------------------------

Write-Output "Starting Parent run book"

$NameP1 = "JohnName1"

$NameP2 = "JohnName2"

Write-Output "Starting child Runbook"

.\Test-Child.ps1 –NameC1 $NameP1 –NameC2 $NameP2

Write-Output "Back in Parent Runbook"

Write-Output $Output

-----------------------------Child-----------------------------

param(
       [string]$NameC1,
       [string]$NameC2
)


Write-Output "Running Child Runbook"

Write-Output "The Name1 is $NameC1"

Write-Output "The Name2 is $NameC2"

[OutputType([string])]
$Output = $NameC1
Write-Output $Output

Does anyone have an idea how to get it back in the Parent Runbook?

Thanks 


Sponsored



Replies

Stanislav Zhelyazkov on Thu, 24 Aug 2017 06:17:31


Hi

My advice here is in the child runbook to have a single output (Write-Output). You can have that output in json format. And your variable will be value in that json. After that child runbook is executed you can capture the output as it will be simple text in json you can convert it to PS Object easily. With psobject you can easily work with that variable.

Gert Humphris ZA on Wed, 30 Aug 2017 22:40:29


Thanks guys I will give it a try.