Skip to content

Commit

Permalink
Copy-DbaCredential: Fix for credentials with square brackets in it's …
Browse files Browse the repository at this point in the history
…name - Issue #9242 (#9243)

Co-authored-by: Ivan Vacho <ivan.vacho@ccs.cz>
  • Loading branch information
ibaxo and Ivan Vacho authored Mar 7, 2024
1 parent 54c8d25 commit e72e1a4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions public/Copy-DbaCredential.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function Copy-DbaCredential {
Write-Message -Level Verbose -Message "Attempting to migrate $credentialName"
try {
$decryptedCred = $decryptedCredentials | Where-Object { $_.Name -eq $credentialName }
$sqlcredentialName = $credentialName.Replace("'", "''")
$sqlcredentialName = $decryptedCred.Quotename
$identity = $decryptedCred.Identity.Replace("'", "''")
$password = $decryptedCred.Password.Replace("'", "''")

Expand All @@ -217,7 +217,7 @@ function Copy-DbaCredential {
}

if ($Pscmdlet.ShouldProcess($destinstance, "Copying $identity ($credentialName)")) {
$destServer.Query("CREATE CREDENTIAL [$sqlcredentialName] WITH IDENTITY = N'$identity', SECRET = N'$password' $cryptoSQL")
$destServer.Query("CREATE CREDENTIAL $sqlcredentialName WITH IDENTITY = N'$identity', SECRET = N'$password' $cryptoSQL")
$destServer.Credentials.Refresh()
Write-Message -Level Verbose -Message "$credentialName successfully copied"
$copyCredentialStatus.Status = "Successful"
Expand Down

0 comments on commit e72e1a4

Please sign in to comment.