Last active
May 14, 2022 02:53
-
-
Save mwallner/367b364639795d504d3980a2687059de 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
function PrintJobWithData { | |
param( | |
[Parameter(Mandatory = $True, ValueFromPipeline = $True)] | |
$job | |
) | |
if ($job.HasMoreData -eq "True") { | |
Write-Output "--- BEGIN $($job.Name) BEGIN ---" | |
try { | |
$job | Receive-Job | |
} | |
finally { | |
Write-Output "--- END $($job.Name) END ---" | |
} | |
} | |
} | |
function MonitorJobs($joblist, $interval) { | |
try { | |
do { | |
$jobstate = $joblist | Get-Job | Where-Object -Property State -eq "Running" | |
$jobstate | Get-Job | ForEach-Object {$_ | PrintJobWithData} | |
Start-Sleep $interval | |
} while ($jobstate) | |
$joblist | Get-Job | ForEach-Object {$_ | PrintJobWithData} | |
} | |
catch { | |
Write-Error ($_.Exception | Format-List -Force | Out-String) -ErrorAction Continue | |
Write-Error ($_.InvocationInfo | Format-List -Force | Out-String) -ErrorAction Continue | |
$joblist | Get-Job | Receive-Job | Write-Output | |
throw | |
} | |
finally { | |
$joblist | Remove-Job -Force | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment