Stop Job - PowerShell


Overview

Stop-Job halts the execution of a running PowerShell job. It is useful for terminating long-running or unresponsive jobs to regain control of the system.

Syntax

Stop-Job [-Id] <string[]> [-WhatIf] [-Confirm] [-PassThru]

Options/Flags

  • -Id: Accepts an array of job names or job IDs to stop. If no -Id is specified, all running jobs are stopped.
  • -WhatIf: Shows what would happen without actually stopping any jobs.
  • -Confirm: Prompts for confirmation before stopping the specified jobs.
  • -PassThru: Returns the stopped job objects.

Examples

Simple usage:

Stop-Job -Id Job1

Stop all running jobs:

Stop-Job

Confirm before stopping:

Stop-Job -Id Job1 -Confirm

Common Issues

  • Error: “Cannot find job with specified name.”
    Solution: Verify that the specified job name or ID is correct. Use Get-Job to list running jobs.
  • Error: “Job is already stopped.”
    Solution: The job is already stopped. Ignore the error.

Integration

Stop-Job can be used in conjunction with other PowerShell commands:

  • Get-Job: To retrieve running or completed jobs.
  • Remove-Job: To permanently remove completed or stopped jobs.