Re-submission of a hanging job (start-work)

I start multiple jobs (using Start-Job) and at the end of my script I do a check to check if the job was longer than X seconds. Then I would like to execute the Running and Failed jobs and restart them until they are successful.

Tasks are named after the server that I would like to work with (for example, using Test-Connection). My problem is I can't figure out how to resubmit assignments!

get-job | where { $_.state -eq "running" } | remove-job -force | start-job -ScriptBlock { echo $_ }

      

  • How can I pass the name of the failed / changed job (s) to the new job that I start?
  • How can I wait for the delete-job to complete before continuing with Start-Job?

Respectfully:)

+3


source to share


1 answer


One way to restart failed jobs:



Start-Job -Name Foo -ScriptBlock {
    $ErrorActionPreference = 'Stop'
    Get-Item C:\DoesNotExists 
} | Wait-Job > $null

Get-Job | ? { $_.State -eq 'Failed' } | % {
    Start-Job -Name $_.Name -ScriptBlock { iex $args[0] } -ArgumentList $_.Command | Wait-Job | Receive-Job
}

      

+3


source







All Articles