Skip to content

Instantly share code, notes, and snippets.

@mwallner
Created December 17, 2018 08:44
Show Gist options
  • Save mwallner/beb18eaf5bea743007349c591b1303bc to your computer and use it in GitHub Desktop.
Save mwallner/beb18eaf5bea743007349c591b1303bc to your computer and use it in GitHub Desktop.
$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