PowerShell Workflow for Mere Mortals: Part 5
Summary : Microsoft Scripting Guy, Ed Wilson, concludes his five-part series about Windows PowerShell Workflow.
Hey, Scripting Guy! I have a number of commands that I want to run against several remote servers. The commands include stuff that must happen prior to something else happening. But then, there are also some things that I would like to happen as fast as possible. Is this permissible? If so, do I have to write two different workflows?
Microsoft Scripting Guy, Ed Wilson, is here. This afternoon I am sipping an awesome cup of Oolong tea with a cinnamon stick, jasmine flower, and lemon grass. The flavor is just about perfect. In the background, I am listening to Ravel . Outside, the sky is dark and it is raining. The thunder seems to punctuate the music.
Note This is the last post in a five-part series about Windows PowerShell Workflow for “mere mortals.” Before you read this post, please read:
PowerShell Workflow for Mere Mortals: Part 1
PowerShell Workflow for Mere Mortals: Part 2
PowerShell Workflow for Mere Mortals: Part 3
PowerShell Workflow for Mere Mortals: Part 4
For more information about workflow, see these Hey, Scripting Guy! Blog posts: Windows PowerShell Workflow .
Well TB, the good news is that you do not need to write two different workflows to enable parallel processing and sequential processing. Windows PowerShell Workflows are flexible enough to handle both in the same workflow.
Adding a sequence activity to a workflow
To add a sequence activity to a Windows PowerShell Workflow, all I need to do is use the Sequence keyword and specify a script block. When I do this, it causes the commands in the sequence script block to run sequentially and in the specified order.
The key concept here is that a Sequence activity occurs within a Parallel activity. The Sequence activity is required when I want commands to run in a particular order. This is because commands running inside a Parallel activity run in an undetermined order.
The commands in the Sequence script block run in parallel with all of the commands in the Parallel activity. But the commands within the Sequence script block run in the order in which they appear in the script block. The following workflow illustrates this technique:
Get-WindowsFeature -Name PowerShell*