CmdID / PowerShell / Cmdlets / Remove
Remove-Job
Deletes a PowerShell background job. PowerShell reference
From the PowerShell reference
10 parameters
Alias rjb
What it does
Deletes a PowerShell background job. The Remove-Job cmdlet deletes PowerShell background jobs that were started by the Start-Job cmdlet or by cmdlets such as Invoke-Command that support the AsJob parameter. You can use Remove-Job to delete all jobs or delete selected jobs. The jobs are identified by their Name, Id, InstanceId, Command, or State. Or, a job object can be sent down the pipeline to Remove-Job. Without parameters or parameter values, Remove-Job has no effect. Since PowerShell 3.0, Remove-Job can delete custom job types, such as scheduled jobs and workflow jobs. For example, Remove-Job deletes the scheduled job, all instances of the scheduled job on disk, and the results of all triggered job instances. If you try to delete a running job, Remove-Job fails. Use the Stop-Job cmdlet to stop a running job. Or, use Remove-Job with the Force parameter to delete a running job. Jobs remain in the global job cache until you delete the background job or close the PowerShell session.
Remove-Job [-Id] <Int32[]> [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]Remove-Job [-Job] <Job[]> [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]Remove-Job [-Name] <String[]> [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]Remove-Job [-InstanceId] <Guid[]> [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]Remove-Job [-Filter] <Hashtable> [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]Remove-Job [-State] <JobState> [-WhatIf] [-Confirm] [<CommonParameters>]Remove-Job [-Command <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Delete a job by using its name
$batch = Get-Job -Name BatchJob
$batch | Remove-JobIdentifyDelete all jobs in a session
Get-Job | Remove-JobIdentifyDelete NotStarted jobs
Remove-Job -State NotStartedIdentifyDelete jobs by using a friendly name
Remove-Job -Name *batch -ForceIdentifyDelete a job that was created by Invoke-Command
$job = Invoke-Command -ComputerName Server01 -ScriptBlock {Get-Process} -AsJob
$job | Remove-JobIdentifyDelete a job that was created by Invoke-Command and Start-Job
$S = New-PSSession -ComputerName Server01
Invoke-Command -Session $S -ScriptBlock {Start-Job -ScriptBlock {Get-Process} -Name MyJob}
Invoke-Command -Session $S -ScriptBlock {Remove-Job -Name MyJob}IdentifyDelete a job by using its InstanceId
$job = Start-Job -ScriptBlock {Get-Process powershell}
$job | Format-List -Property *
Remove-Job -InstanceId ad02b942-8007-4407-87f3-d23e71955872IdentifyIts page in the reference: Remove-Job.
Parameters
-CommandDeletes jobs that include the specified words in the command. You can enter a comma-separated array.-FilterDeletes jobs that satisfy all the conditions established in the associated hash table. 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 workflow jobs and scheduled jobs. It doesn't work on standard background jobs, such as those created by using the Start-Job.
This parameter is introduced in PowerShell 3.0.-ForceDeletes a job even if the job's state is Running. If the Force parameter isn't specified,
Remove-Job doesn't delete running jobs.-IdDeletes background jobs with the specified Id. You can enter a comma-separated array. The job's Id is a unique integer that identifies a job within the current session.
To find a job's Id, use Get-Job without parameters.-InstanceIdDeletes jobs with the specified InstanceId. You can enter a comma-separated array. An InstanceId is a unique GUID that identifies a job.
To find a job's InstanceId, use Get-Job.-JobSpecifies the jobs to be deleted. Enter a variable that contains the jobs or a command that gets the jobs. You can enter a comma-separated array.
You can send job objects down the pipeline to Remove-Job.-NameOnly deletes jobs with the specified friendly name. Wildcards are permitted. You can enter a
comma-separated array.
Friendly names for jobs aren't guaranteed to be unique, even within a PowerShell session. Use the WhatIf and Confirm parameters when you delete files by name.-StateOnly deletes jobs with the specified state. To delete jobs with a state of Running, use the Force parameter.
- AtBreakpoint
- Blocked
- Completed
- Disconnected
- Failed
- NotStarted
- Running
- Stopped
- Stopping
- Suspended
- Suspending-ConfirmPrompts you for confirmation before Remove-Job is run.-WhatIfShows what would happen if Remove-Job runs. The cmdlet isn't run.