Author Posts

January 1, 2012 at 12:00 am

by MattG at 2012-12-17 10:33:57

According to About_Windows_PowerShell_3.0, it is possible to export the Xaml of a workflow. "Workflows are also portable; they can be exported as or imported from XAML files." They don't specify whether or not this can be achieved from within PowerShell, however. For example, I know you can import a workflow's xaml with Import-Module but there is no equivalent Export-* cmdlet to export the Xaml. So my question is: does anyone have any experience exporting the XAML representation of a workflow created in PowerShell? Thanks.

by coderaven at 2012-12-17 11:49:02

Here is the process I currently use when wanting to export and import.

After creating a workflow like this:
Workflow TestWFExport { Get-Process }
You can use it like a normal PowerShell command like by calling TestWFExport.

Now you decide you want to export that command to another computer. Luckily the Get-Command for a workflow has a XamlDefinition. To export the definition:
Get-Command TestWFExport | select -ExpandProperty XamlDefinition | Set-Content C]
At the system you want to import this xaml workflow, just use the Import-Module command and use the path to where the xaml file exist.
Import-Module C]
Keep in mind that this is an example of exporting and importing a single cmdlet/workflow. In this example you see that the Get-Command is smart enough to know the difference between a regular cmdlet (CmdletInfo) and a workflow (WorkflowInfo).

by MattG at 2012-12-17 12:03:14

Fantastic! That's exactly what I was looking for.