CmdID

CmdID / PowerShell / Cmdlets / Stop

Stop-Job

Stops a PowerShell background job. PowerShell reference

From the PowerShell reference 9 parameters Alias spjb

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Stops a PowerShell background job. The Stop-Job cmdlet stops PowerShell background jobs that are in progress. You can use this cmdlet to stop all jobs or stop selected jobs based on their name, ID, instance ID, or state, or by passing a job object to Stop-Job. You can use Stop-Job to stop background jobs, such as those that were started by using the Start-Job cmdlet or the AsJob parameter of any cmdlet. When you stop a background job, PowerShell completes all tasks that are pending in that job queue and then ends the job. No new tasks are added to the queue after this command is submitted. This cmdlet does not delete background jobs. To delete a job, use the Remove-Job cmdlet. Starting in Windows PowerShell 3.0, Stop-Job also stops custom job types, such as WorkflowJobs and instances of ScheduledJobs. To enable Stop-Job to stop a job with custom job type, import the module that supports the custom job type into the session before you run a Stop-Job command, either by using the Import-Module cmdlet or by using or getting a cmdlet in the module. For information about a particular custom job type, see the documentation of the custom job type feature.

Stop-Job [-PassThru] [-Id] <Int32[]> [-WhatIf] [-Confirm] [<CommonParameters>]
Stop-Job [-Job] <Job[]> [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]
Stop-Job [-PassThru] [-Name] <String[]> [-WhatIf] [-Confirm] [<CommonParameters>]
Stop-Job [-PassThru] [-InstanceId] <Guid[]> [-WhatIf] [-Confirm] [<CommonParameters>]
Stop-Job [-PassThru] [-State] <JobState> [-WhatIf] [-Confirm] [<CommonParameters>]
Stop-Job [-PassThru] [-Filter] <Hashtable> [-WhatIf] [-Confirm] [<CommonParameters>]

Stop a job on a remote computer with Invoke-Command

$s = New-PSSession -ComputerName Server01 -Credential Domain01\Admin02 $j = Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-EventLog -LogName System}} Invoke-Command -Session $s -ScriptBlock { Stop-Job -Job $Using:j }Identify

Trips 1 Sigma rule: mediumEventLog Query Requests By Builtin Utilities by Ali Alwashali, Nasreddine Bencherchali (Nextron Systems)

Stop a background job

Stop-Job -Name "Job1"Identify

Stop several background jobs

Stop-Job -Id 1, 3, 4Identify

Stop all background jobs

Get-Job | Stop-JobIdentify

Stop all blocked background jobs

Stop-Job -State BlockedIdentify

Stop a job by instance ID

Get-Job | Format-Table ID, Name, Command, @{Label="State";Expression={$_.JobStateInfo.State}}, InstanceId -AutoIdentify

Stop a job on a remote computer

$j = Invoke-Command -ComputerName Server01 -ScriptBlock {Get-EventLog -LogName System} -AsJob $j | Stop-Job -PassThruIdentify

Trips 1 Sigma rule: mediumEventLog Query Requests By Builtin Utilities by Ali Alwashali, Nasreddine Bencherchali (Nextron Systems)

Its page in the reference: Stop-Job.

Parameters

9 in the PowerShell reference
-FilterSpecifies a hash table of conditions. This cmdlet stops jobs that satisfy every condition. Enter a hash table where the keys are job properties and the values are job property values. This parameter works only on custom job types, such as WorkflowJobs and ScheduledJobs. It does not work on standard background jobs, such as those created by using the Start-Job cmdlet. For information about support for this parameter, see the help topic for the job type. This parameter was introduced in Windows PowerShell 3.0.
-IdSpecifies the IDs of jobs that this cmdlet stops. The default is all jobs in the current session. The ID is an integer that uniquely identifies the job in the current session. It is easier to remember and type than the instance ID, but it is unique only in the current session. You can type one or more IDs, separated by commas. To find the ID of a job, type Get-Job.
-InstanceIdSpecifies the instance IDs of jobs that this cmdlet stops. The default is all jobs. An instance ID is a GUID that uniquely identifies the job on the computer. To find the instance ID of a job, use Get-Job.
-JobSpecifies the jobs that this cmdlet stops. Enter a variable that contains the jobs or a command that gets the jobs. You can also use a pipeline operator to submit jobs to the Stop-Job cmdlet. By default, Stop-Job deletes all jobs that were started in the current session.
-NameSpecifies friendly names of jobs that this cmdlet stops. Enter the job names in a comma-separated list or use wildcard characters (*) to enter a job name pattern. By default, Stop-Job stops all jobs created in the current session. Because the friendly name is not guaranteed to be unique, use the WhatIf and Confirm parameters when stopping jobs by name.
-PassThruReturns an object representing the item with which you are working. By default, this cmdlet does not generate any output.
-StateSpecifies a job state. This cmdlet stops only jobs in the specified state. The acceptable values for this parameter are: - NotStarted - Running - Completed - Failed - Stopped - Blocked - Suspended - Disconnected - Suspending - Stopping For more information about job states, see JobState Enumeration.
-ConfirmPrompts you for confirmation before running the cmdlet.
-WhatIfShows what would happen if the cmdlet runs. The cmdlet is not run.