Azure Automation connector – Content conversion to array

Study Question?

In which format the output of a PowerShell runbook, in Azure Automation, is returned to a Logic App/Flow? 

Let us describe quickly, the Azure Automation PowerShell script and the connection towards Logic App/Flow. The PowerShell script will transfer the results via an array – variable, this by throwing this to the output of the runbook, using the “return”- command.

#example of part of the script
$Sessions = Get-RDSessionHost -CollectionName $CollectionName -ConnectionBroker $ConnectionBroker
[array]$SessionsArray = @()
foreach($Session in $Sessions){
    $SessionsArray += $Session.SessionHost
}
return $SessionsArray #array will be returned to the output of the runbook.

Looking at Logic App/Flow, calling the Azure Automation runbook, by using the action “Create job” (Create Job to run on the hybrid worker)

Calling runbook and second step getting output of the runbook.

In the second step, the output is returned by the PowerShell script via an array. In the screenshot, the output shows us, three items. It looks easy now, adding these lines into a Logic App/Flow variable or data operation – action. But seems that the format type isn’t an array. Adding the content into a compose – action, the output of the compose looks like this.

"SRV.XXXXXXXXX.LOCAL\r\n\r\nSRV.XXXXXXXXX.LOCAL\r\n\r\nSRV.XXXXXXXXX.LOCAL\r\n\r\n"

Carriage Return and Line Feed are visible in the outcome text.


SRV.XXXXXXXXX.LOCAL

SRV.XXXXXXXXX.LOCAL

SRV.XXXXXXXXX.LOCAL


Converting this to a value that can be used to create an array, is resolved by using the “HTML to Text” – action. This will get rid of the carriage return and line feed.

HTML to text – action
Outputs result is a text string

What if the outcome text is larger then the display window. Again a line feed is added to the text string. Extra action is needed to resolve this.

/n is added for each new line in the display window.

What if the outcome text is larger then the display window. Again a line feed is added to the text string. Extra action is needed to resolve this.

Removing line feed.
Outputs string without /n

By splitting the string, we can create an array of all the items into the text string. This is how we can do this:

split(outputs(‘Remove-Return’),’ ‘)

The split is done on the space between two values in the text string.

Final result: Array with all text items

The outcome is an array with all the discovered objects from the runbook. Furthermore, the array can be used in a “For Each” or control action.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.