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

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Copy-SqlServerTrigger

Copy-SqlServerTrigger migrates server triggers from one SQL Server to another. By default, all triggers are copied.

The -Triggers parameter is autopopulated for command-line completion and can be used to copy only specific triggers. If the trigger already exists on the destination, it will be skipped unless -Force is specified. Force drops and recreates the object.

Examples

To copy all Server Triggers from sqlserver2014a to sqlcluster using integrated (Windows) authentication. If a trigger with the same name exists on sqlcluster, it will be skipped.

To copy a single trigger, tg_noDbDrop, from sqlserver2014a to sqlcluster, using SQL credentials for sqlserver2014 and Windows credentials for sqlcluster. If a trigger with the same name exists on sqlcluster, it will be dropped and recreated because -Force was used.

Get-Help

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

Source Code

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

Related commands