Jebarson's dev blog

Coffee, Code

Refer azure runbook activity output in PowerShell expression

When you are creating a runbook with multiple activities, often you will encounter the need of referring an activity output in another activity. Thankfully, all the activities in the runbook can refer another activity in the parameter pane. However, when you have a piece of powershell script which needs to use the same, you don’t have a straight forward way to use it. A macro kind of option like what we have in Visual Studio would be great but as far now we are left with the mercy of our knowledge.

Lets consider a simple scenario. I have a runbook which connects to an Azure SQL database to find out its current pricing tier and it needs to print “The current pricing tier is P2”. Below is how my runbook looks like.

Azure Runbook
Azure Runbook

The “GetSqlDbInfo” activity get the information of the database. The “Write-Output” activity is supposed to print the above mentioned string. You can always refer an “Activity Output” in the parameter but then it will print only the output; it can’t append the output value.

And so the script goes something like below.

$($ActivityOutput[`”GetSqlDbInfo`”])
` (back quote) is the escape character for PowerShell (not to be confused with a single quote).

ActivityOutput is the collection which will hold the activity’s outputs and you can enumerate using the label you have given for the activity. If your activity yielded an object and you need to get a property of it, then your script will be of below.

$($($ActivityOutput[`”GetSqlDbInfo`”]).CurrentServiceObjectiveName)

And therefore for me to print the above message below is how my powershell expression look like.

“The current service tier is $($($ActivityOutput[`”GetSqlDbInfo`”]).CurrentServiceObjectiveName)”

 

Refer azure runbook activity output in PowerShell expression

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top