commands

^

Remove-DbaCustomError

Author Adam Lancaster https://github.com/lancasteradam
Availability Windows, Linux, macOS

 

Synopsis

Removes a user defined message from sys.messages. This command does not support Azure SQL Database.

Description

This command provides a wrapper for the sp_dropmessage system procedure that allows for user defined messages to be removed from sys.messages.

Syntax

Remove-DbaCustomError
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-MessageID] <Int32>]
    [[-Language] <String>]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Remove-DbaCustomError -SqlInstance sqldev01, sqldev02 -MessageID 70001 -Language "French"

Removes the custom message on the sqldev01 and sqldev02 instances with ID 70001 and language French.

Example: 2
PS C:\> Remove-DbaCustomError -SqlInstance sqldev01, sqldev02 -MessageID 70001 -Language "All"

Removes all custom messages on the sqldev01 and sqldev02 instances with ID 70001.

Example: 3
PS C:\> $server = Connect-DbaInstance sqldev01
PS C:\> $newMessage = New-DbaCustomError -SqlInstance $server -MessageID 70000 -Severity 16 -MessageText "test_70000"

Creates a new custom message on the sqldev01 instance with ID 70000, severity 16, and text "test_70000"
To modify the custom message at a later time the following can be done to change the severity from 16 to 20:

PS C:\> $original = $server.UserDefinedMessages | Where-Object ID -eq 70000
PS C:\> $messageID = $original.ID
PS C:\> $severity = 20
PS C:\> $text = $original.Text
PS C:\> $language = $original.Language
PS C:\> $removed = Remove-DbaCustomError -SqlInstance $server -MessageID 70000
PS C:\> $alteredMessage = New-DbaCustomError -SqlInstance $server -MessageID $messageID -Severity $severity -MessageText $text -Language $language -WithLog

The resulting updated message object is available in $alteredMessage.

Required Parameters

-SqlInstance

The target SQL Server instance or instances. This can be a collection and receive pipeline input to allow the function to be executed against multiple SQL Server instances.

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.

Alias
Required False
Pipeline false
Default Value
-MessageID

An integer between 50001 and 2147483647.

Alias
Required False
Pipeline false
Default Value 0
-Language

Language for the message to be removed. The valid values for Language are contained in the Name and Alias columns from sys.syslanguages.

Alias
Required False
Pipeline false
Default Value English
-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

 

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