You want to run PowerShell 3.0 cmdlets through FIM PowerShell Workflow Activity (FIM PS WF) (https://fimpowershellwf.codeplex.com)?
As you may or may not know FIM2010 R2 Service is using a workflow host based on Workflow Foundation 3.5 (.NET 3.5). This means that you can only run PowerShell 2.0 cmdlets through the workflow from FIM.
I just recently did a FIM project were we needed to run some DFS cmdlets to create folder and DFS path when provisioning new users to AD. DFSN module is only available in 3.0 version of PowerShell.
When I try to run my script through PS WF (with PS version 2.0) I got this error:
System.InvalidOperationException: Exception of type 'Microsoft.ResourceManagement.Workflow.WorkflowExtensionException' was thrown. at FimExtensions.FimActivityLibrary.PowerShellActivity.Execute(ActivityExecutionContext context) at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime) at System.Workflow.Runtime.Scheduler.Run()
So I figured I should try to do some kind of “wrapper” to fire a new PS session from within the PS 2.0 session that FIM created through the WF. I tried out a lot of variants and finally landed on one that worked. (Please comment if you know a better/other way to solve this, bare in mind that I`am NO PS guru).
From within FIM Powershell Workflow I called the DFSScript.ps1 with invoke-command, and passed FIM PS WF values to the session:
$username = $fimwf.WorkflowDictionary.usraccountname $displayname = $fimwf.WorkflowDictionary.usrdisplayname Invoke-Command -ComputerName SRV-FIM01 -FilePath C:\FIMRun\Workflows\DFSScript.ps1 -ArgumentList $username, $displayname
Now the key here is to “receive” the params passed from the invoke-command in the DFSScript.ps1 like this:
param ($username,$displayname) $username,$displayname
Now you can use the variables as you have them in the new PS 3.0 session 🙂
Here is an example of the DFSScript.ps1