Orchestrate your scripts with workflows – Part 1

Availables within PowerShell v3, workflows were created to bring you a solution to orchestrate and coordinate your multimachines sequences. Workflows are robust, reliable and handle long running tasks!

According my experience, many peoples know about them, but not so many administrators use them. Let’s have a full visit about using them, and building them.

Write a simple workflow

Writting a workflow is like writting a function, it’s really easy !

Why InlineScript ?

The InlineScript activity runs commands in a shared Windows PowerShell session in a workflow. This activity is valid only in workflows.

It means variables outside the InlineScript can only be used by specifying $using:$yourvar. Exemple from technet page

You can also execute scriptblock on remote target with InlineScript, we’ll see how later in this post.

Advanced workflows technics

Declare parameters

Like a function, you can use parameters with your workflow (of course). By the way, there are limits declaring parameters in a workflow, you can’t use sophisticated parameters, like running test-path, using .net type shortcut like ipadress, etc..

If you use InlineScripts, you don’t have to declare parameters in param section if you use Workflows common parameters with the scope parameter-level ! You can find the complete list of theses parameters here. I’ll explain the ones i found the most usefull.

 

Parallelism

Sequences ( a squence is a group of statements)  can be used between parallel brackets in order to parallelize them. As an exemple is better than all words, here we go !

Another possibility available only in workflows is foreach with -parallel switch !

 

 

Run a workflow

Locally

The easiest solution is to invoke the workflow in the same script like done in the previous example.

Just use the workflow name like you’ll do for a function or a cmdlet !

Remotely

If you want to use remoting in your workflows it’s also possible, and a piece of cake with InlineScript  !

To do this, create the following workflow as example

And run it!

And taddaah!

Ok, this is all for this first part. Next time will talk about:

  • Common parameters
  • Controlling the flow of your workflows
  • Handle XAML in a workflow
  • Troubleshooting workflows

 

Hope you enjoy it!

See ya !