Powershell activity.output empty when running from script.

thomduran
Kilo Explorer

I am attempting to run a Powershell script and push stdout to activity.output.   I have verified when writing the script that it writes to stdout, but when I run the script from a workflow activity.output returns blank.   If I copy this script in as a command in the Run Powershell activity it works just fine.   Any ideas on why the script itself wouldn't be pushing to stdout although I see it that way when running it manually on the server?   When running from a script does it store output to a different variable?   Or is there something I need to do in my script for SNOW to see the output?

Thanks in advance.  

17 REPLIES 17

chadlockwood
Kilo Sage

Thomas,


To get data from my Run PowerShell activity back into my workflow I do the following:



At the end of the PowerShell code, once your payload is created use these three lines:



Write-Output "%output%" #the % signs are required; the text can be anything you want


Write-Output "$($payload_variable_name)" #whatever variable name you used for your payload


Write-Output "%%" #again the % signs are required



In the Sensor Script you will read the "tags" sent by the PowerShell script. The tag is whatever text you put in the first line, so:


var ps_output = tags.output



From there you can parse it as necessary. This works really well for regular text and JSON from PowerShell.



Hope this helps,


Chad


Chad, do you know if this is still best practice with Helsinki and the new PowerShell custom activities?


In a manner of speaking, yes. You still have to identify output by using the "tags" method:


Write-Output "%output%" #the % signs are required; the text can be anything you want


Write-Output "$($payload_variable_name)" #whatever variable name you used for your payload


Write-Output "%%" #again the % signs are required



However, in the outputs of your custom activity, you will define parsing rules, to pass the output of your PowerShell script to the databus. Using the example above, I would create a parsing rule with variable name activityOutput.PSOutput. In this rule, the Source would be executionResult.tags["output"]. You can find the available parsing sources here. This is where the activity designer deviates from my previous post. There is no sensor script on the activity you are designing to interact with your tags variable. If you need to parse data from PowerShell, you will have to use a Run Script to do it, and access the information from the databus. Please see this thread for how to access the databus from your custom activity.