commands

^

New-DbaAgentAlert

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows, Linux, macOS

 

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

Synopsis

Creates a new SQL Server Agent alert

Description

Creates a new SQL Server Agent alert

Syntax

New-DbaAgentAlert
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [-Alert] <String>
    [[-Category] <String>]
    [[-Database] <String>]
    [[-Operator] <String[]>]
    [[-DelayBetweenResponses] <Int32>]
    [-Disabled]
    [[-EventDescriptionKeyword] <String>]
    [[-EventSource] <String>]
    [[-JobId] <String>]
    [[-Severity] <Int32>]
    [[-MessageId] <Int32>]
    [[-NotificationMessage] <String>]
    [[-PerformanceCondition] <String>]
    [[-WmiEventNamespace] <String>]
    [[-WmiEventQuery] <String>]
    [[-NotifyMethod] <String>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> $parms = @{

SqlInstance = "sql01"
Severity = 18
Alert = "Severity 018 - Nonfatal Internal Error"
DelayBetweenResponses = 60
NotifyMethod = "NotifyEmail"
}

PS C:\> $alert = New-DbaAgentAlert @parms

Creates a new alert for severity 18 with the name Severity 018 - Nonfatal Internal Error.
It will send an email to the default operator and wait 60 seconds before sending another email.

Required Parameters

-SqlInstance

The target SQL Server instance or instances

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

The name of the alert to create

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
-Category

The name of the category for the alert

Alias
Required False
Pipeline false
Default Value
-Database

The name of the database to which the alert applies

Alias
Required False
Pipeline false
Default Value
-Operator

The name of the operator to use in the alert

Alias
Required False
Pipeline false
Default Value
-DelayBetweenResponses

The delay (in seconds) between responses to the alert

Alias
Required False
Pipeline false
Default Value 60
-Disabled

Whether the alert is disabled

Alias
Required False
Pipeline false
Default Value False
-EventDescriptionKeyword

The keyword to search for in the event description

Alias
Required False
Pipeline false
Default Value
-EventSource

The source of the event

Alias
Required False
Pipeline false
Default Value
-JobId

The GUID ID of the job to execute when the alert is triggered

Alias
Required False
Pipeline false
Default Value 00000000-0000-0000-0000-000000000000
-Severity

The severity level for the alert. Valid values are 0-25

Alias
Required False
Pipeline false
Default Value 0
-MessageId

The message ID for the alert

Alias
Required False
Pipeline false
Default Value 0
-NotificationMessage

The message to send when the alert is triggered

Alias
Required False
Pipeline false
Default Value
-PerformanceCondition

The performance condition for the alert

Alias
Required False
Pipeline false
Default Value
-WmiEventNamespace

The namespace of the WMI event to use in the alert

Alias
Required False
Pipeline false
Default Value
-WmiEventQuery

The WMI query to use in the alert

Alias
Required False
Pipeline false
Default Value
-NotifyMethod

The method to use to notify the user of the alert. Valid values are 'None', 'NotifyEmail', 'Pager', 'NetSend', 'NotifyAll'. It is NotifyAll by default.
The Pager and net send options will be removed from SQL Server Agent in a future version of Microsoft SQL Server.
Avoid using these features in new development work, and plan to modify applications that currently use these features.

Alias
Required False
Pipeline false
Default Value NotifyAll
Accepted Values None,NotifyEmail,Pager,NetSend,NotifyAll
-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