Return Array of Windows PowerShell Objects in System Center Orchestrator

In this FAQ from John Savill, learn how to return arrays of objects from Windows PowerShell in System Center Orchestrator.

John Savill

October 17, 2013

1 Min Read
Return Array of Windows PowerShell Objects in System Center Orchestrator

Q: I'm trying to return an array of objects from within Windows PowerShell in a System Center Orchestrator Run .Net script and publish it to a data bus--so why aren't I getting the data I expect?

A: The Run .Net script activity will return data in a way you might not expect. Consider the following PowerShell script that you might run in a regular PowerShell window:

$vmimages = Get-AzureVMImage | ft Label

You would receive the labels of all the Azure virtual machine (VM) images into the $vmimages variable. If you ran this within an Orchestrator Run .Net script activity and published the variable to the data bus, you would see a publishing of the type of the returned data rather than the data itself.

The first step is to not use format-table (ft) but instead use this:

$vmimages = Get-AzureVMImage | select-object -expandproperty Label

Next, you need to create your own custom array and add the data into that custom array. Then the custom array (vmArray) is published to the data bus, which will have the actual values. For example:

$vmimages = Get-AzureVMImage | select-object -expandproperty Label$vmArray =@()foreach ($image in $vmimages){    $vmArray += $image}

Thanks to Charles Joy for helping me out with this one!

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like