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:

  1. $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:

  1. $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:

  1. $vmimages = Get-AzureVMImage | select-object -expandproperty Label
  3. $vmArray =@()
  4. foreach ($image in $vmimages)
  5. {
  6.     $vmArray += $image
  7. }

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