Skip to content

Add-SpectreJob

Description

This function adds a Spectre job to the list of jobs you want to wait for with Wait-SpectreJobs.
To retrieve the outcome of the job you need to use the standard PowerShell Receive-Job cmdlet.


Examples

EXAMPLE 1

$jobOutcomes = Invoke-SpectreCommandWithProgress -ScriptBlock {
    param (
        $Context
    )
    $jobs = @()
    $jobs += Add-SpectreJob -Context $Context -JobName "job 1" -Job (Start-Job { Start-Sleep -Seconds 2 })
    $jobs += Add-SpectreJob -Context $Context -JobName "job 2" -Job (Start-Job { Start-Sleep -Seconds 4 })
    Wait-SpectreJobs -Context $Context -Jobs $jobs
    return $jobs.Job
}
$jobOutcomes | Format-SpectreTable -Property Id, Name, PSJobTypeName, State, Command

Parameters

Context

The Spectre context to add the job to. The context object is only available inside Invoke-SpectreCommandWithProgress. https://spectreconsole.net/api/spectre.console/progresscontext/

TypeRequiredPositionPipelineInput
[ProgressContext]true1false

JobName

The name of the job to add.

TypeRequiredPositionPipelineInput
[String]true2false

Job

The PowerShell job to add to the context.

TypeRequiredPositionPipelineInput
[Job]true3false

Syntax

Add-SpectreJob [-Context] <ProgressContext> [-JobName] <String> [-Job] <Job> [<CommonParameters>]