---
title: "Stop-DbaAgentJob"
description: "Stops running SQL Server Agent jobs by calling their Stop() method."
url: "https://dbatools.io/Stop-DbaAgentJob/"
availability: "Windows, Linux, macOS"
tags: ["Job", "Agent"]
author: "Chrissy LeMaire (@cl), netnerds.net"
source: "https://github.com/dataplat/dbatools/blob/master/public/Stop-DbaAgentJob.ps1"
last_updated: "2024-01-01"
---

# Stop-DbaAgentJob

## Synopsis

Stops running SQL Server Agent jobs by calling their Stop() method.

## Description

Stops currently executing SQL Server Agent jobs and returns the job objects for verification after the stop attempt.  
Perfect for halting runaway jobs during maintenance windows, stopping jobs that are causing blocking or performance issues, or clearing job queues before scheduled operations.  
The function automatically skips jobs that are already idle and can optionally wait until jobs have completely finished stopping before returning results.  
Works with individual job names, exclusion filters, or accepts piped job objects from Get-DbaAgentJob and other dbatools commands.

## Syntax

```powershell
Stop-DbaAgentJob
    [-SqlCredential <PSCredential>]
    [-Job <String[]>]
    [-ExcludeJob <String[]>]
    [-Wait]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Stop-DbaAgentJob -SqlInstance <DbaInstanceParameter[]>
    [-SqlCredential <PSCredential>]
    [-Job <String[]>]
    [-ExcludeJob <String[]>]
    [-Wait]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Stop-DbaAgentJob
    [-SqlCredential <PSCredential>]
    [-Job <String[]>]
    [-ExcludeJob <String[]>]
    -InputObject <Job[]>
    [-Wait]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

```

## Examples

### Example 1: Stops all running SQL Agent Jobs on the local SQL Server instance

```powershell
PS C:\> Stop-DbaAgentJob -SqlInstance localhost
```

### Example 2: Stops the cdc.DBWithCDC_capture SQL Agent Job on sql2016

```powershell
PS C:\> Get-DbaAgentJob -SqlInstance sql2016 -Job cdc.DBWithCDC_capture | Stop-DbaAgentJob
```

### Example 3: Stops the cdc.DBWithCDC_capture SQL Agent Job on sql2016

```powershell
PS C:\> Stop-DbaAgentJob -SqlInstance sql2016 -Job cdc.DBWithCDC_capture
```

### Required Parameters

##### -SqlInstance

The target SQL Server instance or instances.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | True |
| Pipeline | false |
| Default Value |  |

##### -InputObject

Accepts SQL Agent job objects from pipeline operations, typically from Get-DbaAgentJob or other dbatools commands.  
This allows you to filter jobs using complex criteria upstream and then pipe the results directly to Stop-DbaAgentJob for processing.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | True |
| Pipeline | true (ByValue) |
| Default Value |  |

### Optional Parameters

##### -SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).  
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.  
For MFA support, please use Connect-DbaInstance.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Job

Specifies which SQL Agent jobs to stop by name. Accepts exact job names from the target instance.  
Use this when you need to stop specific jobs instead of all running jobs. If unspecified, all currently running jobs will be processed.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -ExcludeJob

Specifies SQL Agent job names to exclude from the stop operation. Accepts exact job names from the target instance.  
Use this when you want to stop most jobs but preserve critical ones like backup jobs, monitoring jobs, or maintenance routines during troubleshooting.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Wait

Waits for each job to completely finish stopping before returning results. Without this switch, the function returns immediately after sending the stop command.  
Use this when you need to ensure jobs have fully terminated before proceeding with subsequent operations like maintenance or troubleshooting steps.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.  
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.  
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -WhatIf

If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.

| Property | Value |
| --- | --- |
| Alias | wi |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Confirm

If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.

| Property | Value |
| --- | --- |
| Alias | cf |
| Required | False |
| Pipeline | false |
| Default Value |  |

## Outputs

**Microsoft.SqlServer.Management.Smo.Agent.Job**

Returns one SMO Job object for each job that was stopped. The object represents the job after the stop operation has been initiated (or completed if -Wait is specified).

**Default display properties (via SMO Agent.Job):**

- Name: The name of the SQL Server Agent job
- Enabled: Boolean indicating if the job is enabled
- CurrentRunStatus: The current execution status of the job (Idle, Executing, etc.)
- LastRunOutcome: The outcome of the last job execution (Succeeded, Failed, Retry, Canceled, etc.)
- LastRunDate: DateTime of the most recent job execution
- NextRunDate: DateTime of the next scheduled job execution
- OwnerLoginName: The login name of the job owner
All SMO Job object properties are accessible using Select-Object *. See Microsoft SQL Server Management Objects (SMO) documentation for the complete property list. Note: When -Wait is specified, the function waits until CurrentRunStatus becomes Idle before returning. Without -Wait, the function returns immediately after initiating the stop operation, and CurrentRunStatus may still show Executing.

---

Part of [dbatools](https://dbatools.io/), a free and open source PowerShell module for SQL Server administration. Full command index: https://dbatools.io/commands/
