dbatools is a free PowerShell module with over 300 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


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.


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.

Copy-DbaDatabaseMail -Source sql2014 -Destination sql2016 -Type Profiles

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



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

Source Code

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

Related commands