Skip to content

Limit-ConcurrentJobs

SYNOPSIS

Limit the number of concurrent PowerShell background jobs.

SYNTAX

Limit-ConcurrentJobs [-MaxJobs] <Int32> [[-CheckTimer] <Double>] [[-JobName] <String>] [-AutoRemoveJob]
 [<CommonParameters>]

DESCRIPTION

This function limits the number of concurrent PowerShell background jobs running at a given time. It monitors the specified jobs and pauses execution until the number of running jobs is below the specified limit. Optionally, it can automatically remove completed jobs.

EXAMPLES

EXAMPLE 1

Limit-ConcurrentJobs -MaxJobs 5

Limits the number of concurrent jobs to 5.

EXAMPLE 2

Limit-ConcurrentJobs -MaxJobs 3 -CheckTimer 0.5 -JobName "MyJob*"

Limits the number of concurrent jobs with names matching "MyJob*" to 3, checking every 0.5 seconds.

EXAMPLE 3

Limit-ConcurrentJobs -MaxJobs 10 -AutoRemoveJob

Limits the number of concurrent jobs to 10 and automatically removes completed jobs.

PARAMETERS

-MaxJobs

The maximum number of concurrent jobs allowed to run.

Type: Int32
Parameter Sets: (All)
Aliases: ConcurrentJobs, MaxConcurrentJobs

Required: True
Position: 1
Default value: 0
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False

-CheckTimer

The interval, in seconds, to wait between checks for the number of running jobs. Defaults to 0.1 seconds.

Type: Double
Parameter Sets: (All)
Aliases: PauseTime, PollTimer, WaitTimer

Required: False
Position: 2
Default value: 0.1
Accept pipeline input: False
Accept wildcard characters: False

-JobName

The name or pattern of the jobs to monitor. Defaults to all jobs (`*`).

Type: String
Parameter Sets: (All)
Aliases: Name

Required: False
Position: 3
Default value: *
Accept pipeline input: False
Accept wildcard characters: False

-AutoRemoveJob

A switch to automatically remove completed jobs.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: ClearCompleted

Required: False
Position: 4
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES