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


Copy-SqlServerAgent

This command brings a number of SQL Server Agent-related commands together. With Copy-SqlServerAgent, you can copy all jobs, shared schedules, agent categories, alerts, operators and proxy accounts from one SQL Server to another. It’s less flexible than using the underlying commands individually, but it’s easy and fast.

easy

To disable the jobs once they’ve reached the destination server, use the -DisableJobsOnDestination switch. To disable jobs on the source server, use the -DisableJobsOnSource switch.

Examples

To copy all jobs, shared schedules, agent categories, alerts, operators and proxy accounts from from sqlserver2014a to sqlcluster, using integrated (Windows) authentication. If agent jobs with the same name exist on sqlcluster, they will be skipped.

To copy all jobs, shared schedules, agent categories, alerts, operators and proxy accounts from from sqlserver2014a to sqlcluster, using integrated (Windows) authentication to log into sqlserver2014a and SQL authentication for sqlcluster. If agent jobs with the same name exist on sqlcluster, they will be skipped. To drop existing and recreate and disable jobs on source.

To see what would happen if the command were executed. No actions are actually performed.

From PowerShell, execute   Get-Help Copy-SqlServerAgent -Detailed   for more information on this function. Want to see the source code? See it on GitHub