New‑SqlDscAgentAlert - dsccommunity/SqlServerDsc GitHub Wiki

SYNOPSIS

Creates a new SQL Agent Alert.

SYNTAX

New-SqlDscAgentAlert [-ServerObject] <Server> [-Name] <String> [[-Severity] <Int32>] [[-MessageId] <Int32>]
 [-PassThru] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

This command creates a new SQL Agent Alert on a SQL Server Database Engine instance.

EXAMPLES

EXAMPLE 1

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
New-SqlDscAgentAlert -ServerObject $serverObject -Name 'MyAlert' -Severity 16

Creates a new SQL Agent Alert named 'MyAlert' with severity level 16.

EXAMPLE 2

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | New-SqlDscAgentAlert -Name 'MyAlert' -MessageId 50001

Creates a new SQL Agent Alert named 'MyAlert' for message ID 50001 using pipeline input.

EXAMPLE 3

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$alertObject = $serverObject | New-SqlDscAgentAlert -Name 'MyAlert' -Severity 16 -PassThru

Creates a new SQL Agent Alert and returns the created object.

PARAMETERS

-Force

Forces the action without prompting for confirmation.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-MessageId

Specifies the message ID for the SQL Agent Alert. Valid range is 0 to 2147483647. Cannot be used together with Severity.

Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: 4
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False

-Name

Specifies the name of the SQL Agent Alert to create.

Type: String
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-PassThru

If specified, the created alert object will be returned.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ServerObject

Specifies current server connection object.

Type: Server
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-Severity

Specifies the severity level for the SQL Agent Alert. Valid range is 0 to 25. Cannot be used together with MessageId.

Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

Microsoft.SqlServer.Management.Smo.Server

SQL Server Database Engine instance object.

OUTPUTS

[Microsoft.SqlServer.Management.Smo.Agent.Alert] if passing parameter PassThru,

otherwise none.

NOTES

Either -Severity or -MessageId must be specified (mutually exclusive).

RELATED LINKS

⚠️ **GitHub.com Fallback** ⚠️