Delete a PowerShell background job.

      Remove-Job [-Id] Int32[] [-Force] [-Confirm] [-WhatIf] [CommonParameters]

      Remove-Job [-Command string[]] [-Confirm] [-WhatIf] [CommonParameters]

      Remove-Job [[-InstanceId] Guid[]] [-Force] [-Confirm] [-WhatIf] [CommonParameters]

      Remove-Job [-Job] Job[] [-Force] [-Confirm] [-WhatIf] [CommonParameters]

      Remove-Job [[-Name] string[]] [-Force] [-Confirm] [-WhatIf] [CommonParameters]

      Remove-Job [-State {NotStarted | Running | Completed | Failed | Stopped | Blocked}]
         [-Confirm] [-WhatIf] [CommonParameters]

   -Command string[]
       Remove jobs that include the specified words in the command.

       Delete the job even if the status is "Running".
       Without -Force, Remove-Job will not delete a running job.

   -Id Int32[]
       Delete background jobs with the specified IDs. 

       The ID is an integer that uniquely identifies the job within the current session.
       It is easier to remember and to type than the instance ID, but it is unique only
       within the current session. You can type one or more IDs (separated by commas).
       To find the ID of a job, type "Get-Job" without parameters.

   -InstanceId Guid[]
       Delete jobs with the specified instance IDs.

       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.

   -Job Job[]
       The the jobs to be deleted.
       Enter a variable that contains the job or a command that gets the job.
       You can also pipe a job object to Receive-Job.

   -Name string[]
       Delete only the jobs with the specified friendly names.
       Wildcards are permitted.
       Because the friendly name is not guaranteed to be unique, even within
       the session, use -WhatIf and -Confirm parameters when deleting jobs by name.
   -State JobState
       Delete only jobs with the specified status.
       Valid values are NotStarted, Running, Completed, Stopped, Failed, and Blocked.
       To delete jobs with a status of Running, use -Force.

       Prompt for confirmation before executing the command.

        Describe what would happen if the command was executed without actually executing the command.

Standard Aliases for Remove-Job: rjb

Remove-Job deletes PowerShell background jobs that were started by using Start-Job or the -AsJob parameter of any cmdlet.

When a PowerShell background job is started, the results do not appear immediately. Instead, the command returns an object representing the background job. The job object contains useful information about the job, but it does not contain the results.

To get the results of the command, use Receive-Job. Receive-Job gets the results that have been generated by the time that the Receive-Job command is submitted. If the results are not yet complete, you can run additional Receive-Job commands to get the remaining results.

By default, job results are deleted from the system when you receive them, the -Keep parameter can use used to save the results. To delete the job results, receive them again (without -Keep), close the session, or use Remove-Job to delete the job from the session.


Delete a background job named BatchJob from the current session:

PS C:\> $batch = get-job -name BatchJob
PS C:\> $batch | remove-job

Delete all jobs in the current session:

PS C:\> get-job | remove-job

Delete all jobs from the current session that have not yet been started:

PS C:\> remove-job -state NotStarted

Remove a job that was started on a remote computer with Invoke-Command -AsJob:

PS C:\> $j = invoke-command -computername Server64 -scriptblock {get-process} -asJob
PS C:\> $j | remove-job

Remove a job that was started by using Invoke-Command to run a Start-Job command:

PS C:\> $sess = new-pssession -computername Server64
PS C:\> invoke-command -session $sess -scriptblock {start-job -scriptblock {get-process} -name MyJob}
PS C:\> invoke-command -session $sess -scriptblock {remove-job -name MyJob}

Find the instance ID of a job:

PS C:\> $myjob = start-job -script {get-process powershell}
PS C:\> $myjob | format-list -property *

“The beautiful thing about learning is nobody can take it away from you” ~ B. B. King

Related PowerShell Cmdlets

Get-Job - Get PowerShell background jobs that are running.
Invoke-Command - Run command.

Copyright © 1999-2024
Some rights reserved