MIM WAL: Run PS script outside the Workflow engine: Passing parameters from your script to WorkFlowData

See this blogpost on how to tun PS scrips inside and outside the workflow engine.

Single value return

You have to do this from inside your PS script. Just do a return from your script

  1. Declare a variable in the WorkflowData library


  1. In your code, return the result with the same name as the variable with a prefix “$”

$myOutput = “5551234”

Return $myOutput

Access in the WorkflowData library

[//WorkflowData/myOutput]

Multiple value return

The MIM WAL documentation says return a hashtable of results. This works when the script runs inside the Workflow but when the PS is run outside I discovered that the hashtable returned gets corrupted on the way back, you end up with a strange array table that’s a collections of single records.

Example

$MyProd = “6789955”

$MyProd2 = “455678”

$mytable=@{MyProd=$MyProd;MyProd2=$MyProd2}

Return $mytable

>>>>>>>>>>>>>>>>>>>>>>

I get this return value for $mytable


Looks like an array of screen shots of my records

Solution

You have to create an array of results in your PS, return it and then convert it a hashtable in your code

In the script

$MyProd = “6789955”

$MyProd2 = “455678”

$PSmytable=@((“MyProd”,$MyProd),(“MyProd2”,$MyProd2))

Return $PSmytable

>>>>>>>>>>>>>>>>>>>>>>

In the Workflow

$mytablelist=Powershell -version 3.0 c:\myscripts\test1.ps1

$mytable=@{}

for ( $i = 0; $i -lt $mytablelist.Length; $i += 2 ) {

$mytable.Add($mytablelist[$i],$mytablelist[$i+1]);

}

Return $mytable

>>>>>>>>>>>>>>>>>>>>>

The result returned ($mytablelist) will look like this


This is then successfully converted to a hashtable and you can access it in the Workflowdata library in subsequent activities

[//WorkflowData/MyProd]

[//WorkflowData/MyProd2]

One thought on “MIM WAL: Run PS script outside the Workflow engine: Passing parameters from your script to WorkFlowData

  1. Pingback: MIM 2016 WAL: Running PowerShell scripts in/out the workflow engine | tlktechidentitythoughts

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