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-DbaLogin

This command migrates logins from source to destination SQL Servers. Supports SQL Server versions 2000 and above. Migrates logins with

  • SIDs
  • passwords
  • defaultdb
  • server roles & securables
  • database permissions & securables
  • login attributes (enforce password policy, expiration, language, etc).

By default, all logins with the exception of system (####Example Login## and local (SERVERNAME\administrators) logins are copied. The -Logins parameter is autopopulated for command-line completion and can be used to copy only specific logins.

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

Examples

To copy all logins from sqlserver to sqlcluster, using integrated (Windows) login. If logins with the same name exist on sqlcluster, they will be skipped.

 

To copy only two SQL logins, netnerds and realcajun, as well as one Windows login ‘base\ctrlb’

 

To copy all logins from sqlserver to sqlcluster, using SQL credentials to login to the destination, sqlcluster. If logins with the same name exist on sqlcluster, they will be dropped and recreated because Force was specified.

 

Watch Copy-DbaLogin in action.

Get-Help

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

Source Code

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

Related commands