Skip to content

Instantly share code, notes, and snippets.

@fdcastel
Last active November 1, 2025 08:22
Show Gist options
  • Select an option

  • Save fdcastel/4f1ce07951c433c9e3ed1c8178bec40c to your computer and use it in GitHub Desktop.

Select an option

Save fdcastel/4f1ce07951c433c9e3ed1c8178bec40c to your computer and use it in GitHub Desktop.
Powershell demo showing how to report the status from running jobs.
# Original code by Mike Smith -- https://stackoverflow.com/a/67510672/33244
# Load your jobs here... Note that they periodically report their status.
Start-Job -Name "LoopA" -ScriptBlock { $i = 0; 1..5 | ForEach-Object { Start-Sleep -Seconds 1; $i++; "$i of 5 complete" }; Start-Sleep -Seconds 1; }
Start-Job -Name "LoopB" -ScriptBlock { $i = 0; 1..5 | ForEach-Object { Start-Sleep -Seconds 2; $i++; "$i of 5 complete" }; Start-Sleep -Seconds 1; }
Start-Job -Name "LoopC" -ScriptBlock { $i = 0; 1..5 | ForEach-Object { Start-Sleep -Seconds 3; $i++; "$i of 5 complete" }; Start-Sleep -Seconds 1; }
# Loop and report status
do {
# Interval between updates; change for your application
Start-Sleep -Milliseconds 500
# Snapshot of current jobs
$jobs = Get-Job
# Report status
Clear-Host
$jobs `
| Select-Object Name, State, @{Name = "LastMsg"; Expression = { $_ | Receive-Job -Keep | Select-Object -Last 1 } } `
| Format-Table
} until (-not ($jobs | Where-Object State -eq "Running"))
# Clean up.
Get-Job | Remove-Job -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment