Execute workflows in strict order?

Hello, dear coleagues.

As I know workflows are not executed in strict order. For example, 

workflow Test-WFConnection {

  param(

    [string[]]$Computers

  )

    foreach -parallel -ThrottleLimit 20 ($computer in $computers) {
        write-host "PC name: " $Computers
}

Test-WFConnection -Computers $Computers

Of course, you know that names of PCs will be output in console not in order they will input.

Quote from PowerShell Workflows: The Basics

If you are running workflow activities in parallel there are no guarantees as to the order in which data will be returned.

You cannot assume that one piece of data will be returned before another.

That means, there is now way to dicrease time of execution, if you need to follow strict order?

Thanks.

February 14th, 2015 6:24pm

Just because a workflow won't do it doesn't mean it can't be done.  

While it is more work to code, you can use runspaces to run tasks in parallel and control the order that the data will be returned.

http://blogs.technet.com/b/heyscriptingguy/archive/2013/09/29/weekend-scripter-max-out-powershell-in-a-little-bit-of-time-part-2.aspx

Free Windows Admin Tool Kit Click here and download it now
February 14th, 2015 6:48pm

What is the point of a workflow that does not use parallelism.  If you want order to the output just sort it.

February 15th, 2015 12:46am

Hello, this is bad example I wrote, but I need to know if powershell can execute script in parallel but in strict order of input and output data. Thanks. 
Free Windows Admin Tool Kit Click here and download it now
February 15th, 2015 5:41pm

Hello, this is bad example I wrote, but I need to know if powershell can execute script in parallel but in strict order of input and output data. Thanks. 

Impossible to do.  Parallel says start all processes at the same time.  They will complete when they are done and totally independently.

If you want order do not use a workflow.

February 15th, 2015 5:44pm

Understand, but only workflows allow parallel execution of script?
Free Windows Admin Tool Kit Click here and download it now
February 15th, 2015 5:49pm

Understand, but only workflows allow parallel execution of script?
No, you can run parallel execution in runspaces, and control the order in that the data will be returned from each one.  It will be up to you to manually create the runspaces, submit the task that will be run to each one, monitor them for completion, and retrieve the data from them.  As I said earlier, it is more work to code, but it gives you the ability to control the order that data will be
February 15th, 2015 5:51pm

Understand, but only workflows allow parallel execution of script?

No, you can run parallel execution in runspaces, and control the order in that the data will be returned from
Free Windows Admin Tool Kit Click here and download it now
February 15th, 2015 5:58pm

The order that the data is input is a function of whatever you used to get the data.  If you need to start the runspace threads in a different order than you received the data, you can do that by sorting the input into the right order before you start, but that's no different that using a workflow.
February 15th, 2015 6:05pm

Guys, thanks for your answer.

So I asked the abstract question, this discussion can be closed. 

I'll try to write script and ask for your help in case of specific problems.

Have a nice day.

Free Windows Admin Tool Kit Click here and download it now
February 18th, 2015 3:43am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics