dbatools is a free PowerShell module with over 180 SQL Server administration, best practice and migration commands included.


Copy-SqlCustomError

This command migrates custom errors (user defined messages) from one SQL Server to another. By default, all custom errors are copied. The -CustomErrors parameter is autopopulated for command-line completion and can be used to copy only specific custom errors.

If the custom error already exists on the destination, it will be skipped unless -Force is specified. Force drops and recreates the custom error.

Examples

To copy all server custom errors from sqlserver2014a to sqlcluster, using integrated (Windows) authentication. If custom errors with the same name exist on sqlcluster, they will be skipped.

To copy a single custom error, the custom error with ID number 6000 from sqlserver2014a to sqlcluster, using SQL credentials for sqlserver2014a and Windows credentials for sqlcluster. If a custom error with the same name exists on sqlcluster, it will be updated because -Force was used.

To see what would happen if the command were executed using force

* Interesting fact, if you drop the us_english version, all the other languages will be dropped for that specific ID as well. Also, the us_english version must be created first.

Get-Help

From PowerShell, execute Get-Help Copy-SqlCustomError -Detailed for more information on this function.

Source Code

Want to see the source code? View Copy-SqlCustomError.ps1 on GitHub
 

Related commands