commands

^

New-DbaAgentAlertCategory

Author Patrick Flynn (@sqllensman)
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out New-DbaAgentAlertCategory on GitHub.
Want to see the Bill Of Health for this command? Check out New-DbaAgentAlertCategory.

Synopsis

Creates new SQL Agent alert categories for organizing and managing database alerts.

Description

Creates custom alert categories in SQL Server Agent to help organize and group related alerts for better management and monitoring.
Alert categories allow DBAs to logically group alerts by function, severity, or responsibility, making it easier to assign different categories to different teams or escalation procedures.
This is particularly useful in environments with many alerts where categorization helps with organization, reporting, and maintenance workflows.
Returns the newly created alert category objects that can be immediately used when configuring SQL Agent alerts.

Syntax

New-DbaAgentAlertCategory
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [-Category] <String[]>
    [-Force]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> New-DbaAgentAlertCategory -SqlInstance sql1 -Category 'Category 1'

Creates a new alert category with the name 'Category 1'.

Example: 2
PS C:\> 'sql1' | New-DbaAgentAlertCategory -Category 'Category 2'

Creates a new alert category with the name 'Category 2'.

Required 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.

Alias
Required True
Pipeline true (ByValue)
Default Value
-Category

Specifies the name or names of the alert categories to create in SQL Server Agent.
Use descriptive names that reflect how you organize alerts, such as 'Database Errors', 'Performance Issues', or 'Security Events'.
Multiple categories can be created in a single operation by providing an array of category names.

Alias
Required True
Pipeline false
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.

Alias
Required False
Pipeline false
Default Value
-Force

Bypasses confirmation prompts and creates the alert categories without user interaction.
Use this parameter in automated scripts or when you're confident about the category names being created.

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.

Alias
Required False
Pipeline false
Default Value False
-WhatIf

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

Alias wi
Required False
Pipeline false
Default Value
-Confirm

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

Alias cf
Required False
Pipeline false
Default Value