Orchestrate your scripts with workflows – Part 2

As we saw in first part of this posts serie. Workflows are very convenients, but they lack things to be the true killer in PowerShell. The first missing thing is a real way to control your workflow flow !

Control a worklow execution

If we speak about orchestration it’s important to consider when your worflow can be suspended, or backup variables when a computer/server reboots. Differents options exist:

  • Checkpoint-Workflow : Where you can stop & resume the workflow

Note that if you really want to suspens the workflow, you must use Suspend-Job -Force

  • $PSPersistencePreference is used to indicate if your workflow can be suspended and/or resumed after every command
Now you can control the execution of your workflows like you do with your jobs, but one thing is missing here… How debug workflows, because it’s kinda cloudy here 😉

Debug workflows

The first thing to know when you want to debug your workflows is to use Write-Output instead of Write-Host if you want something to be traced.

Once your workflow has started, let’s look at what is happening on it.


If we had an error in our workflow, i can get the error like this


You can have detailled information about each inlinescript, but how about going deeper in the debugging without using PowerShell jobs ?

We now have a beautiful trace in $pshome\traces\PSTrace.etl

workflow6You should now be able to diagnostic your workflows even if they are already in production.

This is all regarding workflows on this blog, but if you want to learn more about them have a look to “man about_workflowCommonParameters” on your PowerShell console, you’ll be surprised with all hidden gems.