MIM 2016 WAL: Running PowerShell scripts in/out the workflow engine

Lets talk about running PowerShell scripts in the MIM WAL.  There are two options

  1. Run the PS script in the Workflow engine. I cannot tell you enough about the benefits of doing this. Its really your first choice to make things easier.
  2. Run the PS script outside the Workflow engine.  Sometimes the only option due to some product limitations.

Run PS script in the Workflow engine: Passing parameters to your script

Lets say we want

  • AccountName

To be passed to our script then we do this in the activity

  1. Set Input type to “Named Parameters”
  2. Declare the attribute we want and a named variable

mimwalps1

In the PS script window

  1. Declare Param at the top. It must be the first line in the code
  2. Declare your code

mimwalps2

Run PS script in the Workflow engine: Passing parameters from your script to WorkFlowData

Lets say we want to pass a result out of our script to a WorkflowData variable, you

  1. Declare a variable in the WorkflowData library

mimwalps3

  1. Return the result with the same name as the variable with a prefix “$”

mimwalps4

Run PS script outside the Workflow engine: Passing parameters into your script

Lets say we want to run our script outside the workflow engine because we want to use Lithnet PS which is a Dotnet 4.0 compiled module. If you encounter Dotnet issues with Active Directory module (version 3.0 and greater is compiled in Dotnet 4.0 and greater) see this blogpost here for a workaround.

  1. Declare the variable to contain the attribute value

mimwalps5

  1. In your script declare Param as the first line and declare the command to call and specify the PS version. The format is “Powershell -version 3.0 myPSfilepath myParam”

mimwalps6

Run PS script outside the Workflow engine: Passing parameters from your script to WorkfFlowData

You have to do this from inside your PS script. Here is an example

#Write the info to the workflowdata

#Write a Identifier variable

$fimWF.WorkflowDictionary.Add(“ApproverID”,[Microsoft.ResourceManagement.WebServices.UniqueIdentifier]$MyRequestApprover)

$fimWF.WorkflowDictionary.Add(“TargetRequestor”,[Microsoft.ResourceManagement.WebServices.UniqueIdentifier]$MyRequestTarget)

$fimWF.WorkflowDictionary.Add(“AppAccessRequestor”,[Microsoft.ResourceManagement.WebServices.UniqueIdentifier]$MyRequestor)

#Write a String variable

$fimWF.WorkflowDictionary.Add(“ProdName”,”SAP”)

$fimWF.WorkflowDictionary.Add(“TargetRequestorForAppList”,$MyRequestTarget)