Created
December 17, 2018 08:44
-
-
Save mwallner/beb18eaf5bea743007349c591b1303bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = "Stop" | |
$scriptBlk = { | |
Write-Output "this is some output" | |
Start-Sleep 5 | |
Write-Output "yup, yup" | |
} | |
$jobs = @() | |
$jobs += Start-Job $scriptBlk | |
$jobs += Start-Job $scriptBlk | |
$jobs += Start-Job $scriptBlk | |
function PrintJobWithData { | |
param( | |
[Parameter(Mandatory = $True, ValueFromPipeline = $True)] | |
$job | |
) | |
if ($job.HasMoreData -eq "True") { | |
Write-Output "--- Job $($job.Name)" | |
$job | Receive-Job | |
} | |
} | |
do { | |
$jobstate = $jobs | Get-Job | Where-Object -Property State -eq "Running" | |
$jobstate | Get-Job | % {$_ | PrintJobWithData} | |
Start-Sleep 2 | |
} while ($jobstate) | |
$jobs | Get-Job | % {$_ | PrintJobWithData} | |
$jobs | Remove-Job |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment