...
Code Block | ||||
---|---|---|---|---|
| ||||
$jobScript = { Param ( [Uri] $masterUrl, [string] $jobChain, [int] $pollInterval=10 ) Import-Module JobScheduler if ( $masterUrl ) { $js = Use-JobSchedulerMaster $masterUrl } $order = Add-JobSchedulerOrder -JobChain $jobChain While ( ( $order | Get-JobSchedulerOrder -NoCache ).StartTime ) { Start-Sleep -Seconds $pollInterval } $order | Get-JobSchedulerOrderHistory } echo "begin of test script" $jobs = @() $jobs += Start-Job -ScriptBlock $jobScript -Argumentlist localhost:4444,/some_path/some_job_chain $jobs += Start-Job -ScriptBlock $jobScript -Argumentlist localhost:4444,/some_path/some_other_job_chain $orderHistory = $jobs | Wait-Job | Receive-Job for( $i=0; $i -le $orderHistory.length; $i++ ) { echo "order '$($orderHistory[$i].id)' completed with state '$($orderHistory[$i].State)' at '$($orderHistory[$i].EndTime)'" } echo "end of test script" |
Explanations
- Line 1 - 1518: defines the native PowerShell job.
- The cmdlets used are the same as for the previous sample.
- The native PowerShell job returns the history for the newly created order.
- Line 1923 - 24: Starts the native PowerShell job
- Line 2026: Pipes the native PowerShell job to the native
Wait-Job
cmdlet that forces the script to wait for completion. The result is then piped to theReceive-Job
cmdlet that returns the output of the native PowerShell job. - Line 28 - 31: The job output is retrieved per native PowerShell job.