You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Backup-DbaDbCertificate - Handle DMK-encrypted certs when DecryptionPassword is also provided
Restores dbatoolsci_AGCert to DMK encryption (required for AG endpoint auth).
Fixes Backup-DbaDbCertificate to check PrivateKeyEncryptionType: when a cert's
private key is encrypted by the database master key, skip DecryptionPassword and
use the 3-param export overload instead of the 4-param one that SQL Server rejects.
Updates the "all instance" backup test to use containment checks instead of an
exact count, since the DMK cert will now be backed up successfully.
Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
Copy file name to clipboardExpand all lines: public/Backup-DbaDbCertificate.ps1
+18-9Lines changed: 18 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -225,15 +225,24 @@ function Backup-DbaDbCertificate {
225
225
226
226
# because the password shouldn't go to memory...
227
227
if ($EncryptionPassword.Length-gt0-and$DecryptionPassword.Length-gt0) {
228
-
229
-
Write-Message-Level Verbose -Message "Both passwords passed in. Will export both cer and pvk."
230
-
231
-
$cert.export(
232
-
$exportPathCert,
233
-
$exportPathKey,
234
-
($EncryptionPassword|ConvertFrom-SecurePass),
235
-
($DecryptionPassword|ConvertFrom-SecurePass)
236
-
)
228
+
if ($cert.PrivateKeyEncryptionType-eq [Microsoft.SqlServer.Management.Smo.PrivateKeyEncryptionType]::MasterKey) {
229
+
Write-Message-Level Verbose -Message "Both passwords passed in but private key of $certName is encrypted by the database master key. DecryptionPassword will be ignored."
230
+
231
+
$cert.export(
232
+
$exportPathCert,
233
+
$exportPathKey,
234
+
($EncryptionPassword|ConvertFrom-SecurePass)
235
+
)
236
+
} else {
237
+
Write-Message-Level Verbose -Message "Both passwords passed in. Will export both cer and pvk."
0 commit comments