Lets talk about running PowerShell scripts in the MIM WAL. There are two options
- 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.
- 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
To be passed to our script then we do this in the activity
- Set Input type to “Named Parameters”
- Declare the attribute we want and a named variable
In the PS script window
- Declare Param at the top. It must be the first line in the code
- Declare your code
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
- Declare a variable in the WorkflowData library
- Return the result with the same name as the variable with a prefix “$”
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.
- Declare the variable to contain the attribute value
- 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”. Something to Note. If you are passing a parameter that has a space e.g “Tom Brown”, what you will see is that it will be treated as 2 parameters in your PS, you have to enclose it in a single quote to prevent this mixup. so in your parameter declaration above for say displayname you will use “‘”+[//Target/DisplayName] + “‘”
Run PS script outside the Workflow engine: Passing parameters from your script to WorkfFlowData
See my blogpost on how to do this