Thor Logo dbatools

Remove-DbaAgentOperator

View Source
Tracy Boggiano (@TracyBoggiano), databasesuperhero.com
Windows, Linux, macOS

Synopsis

Removes SQL Server Agent operators from one or more instances.

Description

Removes SQL Server Agent operators from specified instances, cleaning up notification contacts that are no longer needed.

Operators are notification contacts used by SQL Server Agent to send alerts about job failures, system issues, or other events. This function helps you remove outdated operator accounts when employees leave, contact information changes, or you need to consolidate notification lists.

The function safely handles dependencies and provides detailed status output for each removal operation, making it suitable for both interactive cleanup and automated operator management scripts.

Syntax

Remove-DbaAgentOperator
    [-SqlInstance <DbaInstanceParameter[]>]
    [-SqlCredential <PSCredential>]
    [-Operator <String[]>]
    [-ExcludeOperator <String[]>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Remove-DbaAgentOperator
    [-SqlInstance <DbaInstanceParameter[]>]
    [-SqlCredential <PSCredential>]
    [-Operator <String[]>]
    [-ExcludeOperator <String[]>]
    -InputObject <Operator[]>
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Remove-DbaAgentOperator -SqlInstance sql01 -Operator DBA

This removes an operator named DBA from the instance.

Example: 2
PS C:\> Get-DbaAgentOperator -SqlInstance SRV1 | Out-GridView -Title 'Select SQL Agent operator(s) to drop' -OutputMode Multiple | Remove-DbaAgentOperator

Using a pipeline this command gets all SQL Agent operator(s) on SRV1, lets the user select those to remove and then removes the selected SQL Agent alert category(-ies).

Required Parameters

-InputObject

Accepts SQL Server Agent operator objects from Get-DbaAgentOperator for pipeline operations.
This parameter enables filtering operators before removal and supports interactive selection workflows using Out-GridView.

PropertyValue
Alias
RequiredTrue
Pipelinetrue (ByValue)
Default Value

Optional Parameters

-SqlInstance

The target SQL Server instance or instances. You must have sysadmin access and server version must be SQL Server version 2000 or greater.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-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.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-Operator

Specifies the SQL Server Agent operator names to remove from the instance. Accepts multiple operator names for bulk removal.
Use this when you need to remove specific operators by name, such as when employees leave or contact information becomes outdated.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-ExcludeOperator

Specifies operator names to skip during removal operations. Useful when removing multiple operators but want to preserve certain ones.
Use this to protect critical operators from accidental deletion when performing bulk removals or scripted cleanup operations.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-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.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse
-WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

PropertyValue
Aliaswi
RequiredFalse
Pipelinefalse
Default Value
-Confirm

Prompts you for confirmation before executing any changing operations within the command.

PropertyValue
Aliascf
RequiredFalse
Pipelinefalse
Default Value