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

By using password decryption techniques provided by Antti Rantasaari (NetSPI, 2014), this script migrates SQL Server Credentials from one server to another, while maintaining login names and passwords.

This command requires sysadmin access on both the SQL Server and the Windows server. If accessing remote servers, Remote Registry must enabled and accessible by the account running the script.

Credit: Antti Rantasaari, NetSPI
License: BSD 3-Clause

By default, all credentials are migrated. The -Credentials parameter is autopopulated for command-line completion and can be used to copy only specific credentials.

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

Examples

To copy all credentials from sqlserver2014a to sqlcluster, using Windows credentials. If credentials with the same name exist on sqlcluster, they will be skipped.

Copy-SqlCredential -Source sqlserver2014a -Destination sqlcluster

To copy only two credentials, AgentCredential and FileShare, from sqlserver2014a to sqlcluster, using SQL credentials for sqlserver2014a and Windows credentials for sqlcluster. If a credential with the same name exists on sqlcluster, it will be dropped and recreated because -Force was used.

Copy-SqlCredential -Source sqlserver2014a -Destination sqlcluster -Credentials AgentCredential, FileShareCred -SourceSqlCredential sqladmin -Force

To see what would happen if the command were executed

Copy-SqlCredential -Source sqlserver2014a -Destination sqlcluster -WhatIf

Get-Help

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

Source Code

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

Related commands