PowerShell Logo Small

Remove-Job



This is the built-in help made by Microsoft for the command 'Remove-Job', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Deletes a Windows PowerShell background job.

SYNTAX


Remove-Job [-Id] <Int32[]> [-Force] [-Confirm] [-WhatIf] [<CommonParameters>]
Remove-Job [-Command [<String[]>]] [-Confirm] [-WhatIf] [<CommonParameters>]
Remove-Job [-Filter] <Hashtable> [-Force] [-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 | Suspended | Disconnected | Suspending | Stopping | AtBreakpoint} [-Confirm] [-WhatIf]
[<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


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


You can use this cmdlet to delete all jobs or delete selected jobs based on their name, ID, instance ID, command, or state, or by passing a job object to Remove-Job. Without
parameters or parameter values, Remove-Job has no effect.


Beginning in Windows PowerShell 3.0, you can use the Remove-Job cmdlet to delete custom job types, such as scheduled jobs and workflow jobs. If you use Remove-Job to delete
a scheduled job, it deletes the scheduled job and deletes all instances of the scheduled job on disk, including the results of all triggered job instances.


Before deleting a running job, use the Stop-Job cmdlet to stop the job. If you try to delete a running job, the command fails. You can use the Force parameter of Remove-Job
to delete a running job.


If you do not delete a background job, the job remains in the global job cache until you close the session in which the job was created.



<

RELATED LINKS

Online Version: http://technet.microsoft.com/library/hh849742.aspx
Get-Job
Invoke-Command
Receive-Job
Resume-Job
Start-Job
Stop-Job
Suspend-Job
Wait-Job
about_Job_Details
about_Remote_Jobs
about_Jobs

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>$batch = Get-Job -Name BatchJob
PS C:\>$batch | Remove-Job



These commands delete a background job named BatchJob from the current session. The first command uses the Get-Job cmdlet to get an object representing the job, and then it
saves the job in the $batch variable. The second command uses a pipeline operator (|) to send the job to the Remove-Job cmdlet.

This command is equivalent to using the Job parameter of Remove-Job, for example, "remove-job -job $batch".






-------------------------- EXAMPLE 2 --------------------------

PS C:\>Get-job | Remove-Job



This command deletes all of the jobs in the current session.






-------------------------- EXAMPLE 3 --------------------------

PS C:\>Remove-Job -State NotStarted



This command deletes all jobs from the current session that have not yet been started.






-------------------------- EXAMPLE 4 --------------------------

PS C:\>Remove-Job -Name *batch -Force



This command deletes all jobs with friendly names that end with "batch" from the current session, including jobs that are running.

It uses the Name parameter of Remove-Job to specify a job name pattern, and it uses the Force parameter to ensure that all jobs are removed, even those that might be in
progress.






-------------------------- EXAMPLE 5 --------------------------

PS C:\>$j = Invoke-Command -ComputerName Server01 -ScriptBlock {Get-Process} -AsJob
PS C:\>$j | Remove-Job



This example shows how to use the Remove-Job cmdlet to remove a job that was started on a remote computer by using the AsJob parameter of the Invoke-Command cmdlet.

The first command uses the Invoke-Command cmdlet to run a job on the Server01 computer. It uses the AsJob parameter to run the command as a background job, and it saves the
resulting job object in the $j variable.

Because the command used the AsJob parameter, the job object is created on the local computer, even though the job runs on a remote computer. As a result, you use local
commands to manage the job.

The second command uses the Remove-Job cmdlet to remove the job. It uses a pipeline operator (|) to send the job in $j to Remove-Job. Note that this is a local command. A
remote command is not required to remove a job that was started by using the AsJob parameter.






-------------------------- EXAMPLE 6 --------------------------

The first command uses the New-PSSession cmdlet to create a PSSession (a persistent connection) to the Server01 computer. A persistent connection is required when running a
Start-Job command remotely. The command saves the PSSession in the $s variable.
PS C:\>$s = New-PSSession -ComputerName Server01

The second command uses the Invoke-Command cmdlet to run a Start-Job command in the PSSession in $s. The job runs a Get-Process command. It uses the Name parameter of
Start-Job to specify a friendly name for the job.
PS C:\>Invoke-Command -Session $s -ScriptBlock {Start-Job -ScriptBlock {Get-Process} -Name MyJob}

The third command uses the Invoke-Command cmdlet to run a Remove-Job command in the PSSession in $s. The command uses the Name parameter of Remove-Job to identify the job to
be deleted.
PS C:\>Invoke-Command -Session $s -ScriptBlock {Remove-Job -Name MyJob}



This example shows how to remove a job that was started by using Invoke-Command to run a Start-Job command. In this case, the job object is created on the remote computer
and you use remote commands to manage the job.






-------------------------- EXAMPLE 7 --------------------------

The first command uses the Start-Job cmdlet to start a background job. The command saves the resulting job object in the $j variable.
PS C:\>$j = Start-Job -ScriptBlock {Get-Process Powershell}

The second command uses a pipeline operator (|) to send the job object in $j to the Format-List cmdlet. The Format-List command uses the Property parameter with a value of *
(all) to display all of the properties of the job object in a list.The job object display shows the values of the ID and InstanceID properties, along with the other
properties of the object.
PS C:\>$j | Format-List -Property *

HasMoreData : False
StatusMessage :
Location : localhost
Command : get-process powershell
JobStateInfo : Failed
Finished : System.Threading.ManualResetEvent
InstanceId : dce2ee73-f8c9-483e-bdd7-a549d8687eed
Id : 1
Name : Job1
ChildJobs : {Job2}
Output : {}
Error : {}
Progress : {}
Verbose : {}
Debug : {}
Warning : {}
StateChanged :

The third command uses a Remove-Job command to remove the job from the current session. To generate the command, you can copy and paste the InstanceID value from the object
display.To copy a value in the Windows PowerShell console, use the mouse to select the value, and then press Enter to copy it. To paste a value, right-click.
PS C:\>Remove-Job -InstanceID dce2ee73-f8c9-483e-bdd7-a549d8687eed



This example shows how to remove a job based on its instance ID.