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


Copy-SqlDatabaseMail

This function migrates database mail configuration values, mail servers, accounts and profiles from one SQL Server to another. By default, all database mail objects are copied.

To migrate only one object type use the -Type parameter and specify ConfigurationValues, MailServers, Profiles, or Accounts.

The -ConfigurationValues, -MailServers, -Profiles, and -Accounts parameters are autopopulated for command-line completion and can be used to copy only specific objects.

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

Examples

To copy over all Database Mail settings from sqlserver\instance to sqlcluster using Windows authentication

To copy over all Database Mail settings from sql2014 to sql2016 using SQL authentication.

To copy over all Database Mail Profiles from sql2014 to sql2016.

To copy over just the AccountRetryAttempts configuration value and smtp.ad.local mail server

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