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