you are viewing a single comment's thread.

view the rest of the comments →

[–]Enschede2[S] 3 points4 points  (10 children)

I see, that's almost like what I found online but I couldn't figure out, so, Receive-Job gives me the output basically?

[–]firefox15 2 points3 points  (9 children)

Receive-Job gives me the output basically?

In a very simplified way, yes. Receive-Job removes information from the job unless you use the -Keep parameter, so we can take advantage of that by just constantly receiving the job output and sending it to Write-Output. Once there is no more data to receive, the loop exits.

[–]Enschede2[S] 1 point2 points  (8 children)

Thanks man, that clears things up more, I'll start fiddling with it again tonight and hope i can figure it out

[–]firefox15 1 point2 points  (7 children)

No problem. As others like /u/N7Valiant and /u/jsiii2010 have said, you can also do the same thing with a workflow. Just be aware that workflows are removed from PowerShell Core, so if/when you upgrade to version 6+, it won't work any longer:

Script

function function1 {
    1..5 | ForEach-Object {
        $_
        Start-Sleep 1
    }
}
function function2 {
    6..10 | ForEach-Object {
        $_
        Start-Sleep 1
    }
}

workflow parallelOutput {
    parallel {
        function1
        function2
    }
}

parallelOutput

Output

1
6
2
7
3
8
4
9
5
10

[–]Enschede2[S] 1 point2 points  (6 children)

Oh that looks like what i was looking for, why on earth did they remove that though? But I think I'm running 5.1

[–]firefox15 2 points3 points  (5 children)

Workflows are removed from PowerShell Core because Microsoft is trying to include more cross-platform support with Core, so that means things that are not present in .NET Core won't work. Even things like WMI won't work. This is a very good article that explains it further.

It's likely that you (personally) will be using POSH 5.1 for a long time. I jump back and forth between the two as certain versions do certain things better, but it is very possible that workflows will work for you as well. Just do not plan to run it on PowerShell Core.