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
Copy file name to clipboardExpand all lines: public/Add-DbaAgDatabase.ps1
+52Lines changed: 52 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -83,6 +83,12 @@ function Add-DbaAgDatabase {
83
83
When enabled, Restore-DbaDatabase uses the replica's default data and log directories instead of attempting to replicate the primary's folder structure.
84
84
This is automatically set to true when the primary and replica servers run on different operating system platforms (e.g., Windows primary with Linux replica).
85
85
86
+
.PARAMETERMasterKeySecurePassword
87
+
Password for creating or opening the database master key on secondary replicas when adding TDE-encrypted databases.
88
+
When a database is protected by Transparent Data Encryption (TDE), the certificate used to protect the Database Encryption Key must exist on every secondary replica.
89
+
Providing this parameter together with SharedPath allows the command to automatically copy the TDE certificate from the primary to each secondary replica.
90
+
If the secondary already has a master key, this password is used to create one if it is missing.
91
+
86
92
.PARAMETERWhatIf
87
93
Shows what would happen if the command were to run. No actions are actually performed.
88
94
@@ -242,6 +248,9 @@ function Add-DbaAgDatabase {
242
248
[switch]$SkipReuseSourceFolderStructure,
243
249
[Parameter(ParameterSetName='NonPipeline')]
244
250
[Parameter(ParameterSetName='Pipeline')]
251
+
[Security.SecureString]$MasterKeySecurePassword,
252
+
[Parameter(ParameterSetName='NonPipeline')]
253
+
[Parameter(ParameterSetName='Pipeline')]
245
254
[switch]$EnableException
246
255
)
247
256
@@ -365,6 +374,49 @@ function Add-DbaAgDatabase {
365
374
}
366
375
}
367
376
377
+
# For TDE-encrypted databases, the master certificate must exist on every secondary replica
378
+
# before a backup can be restored or automatic seeding can succeed.
379
+
if ($db.EncryptionEnabled-and$db.HasDatabaseEncryptionKey-and$db.DatabaseEncryptionKey.EncryptorType-eq"ServerCertificate") {
Stop-Function-Message "Failed to copy TDE certificate to all replicas for database $($db.Name)."-Continue
414
+
}
415
+
} else {
416
+
Write-Message-Level Warning -Message "Database $($db.Name) is TDE-encrypted with certificate '$encryptorName', but no SharedPath was provided. The TDE certificate must exist on all secondary replicas before the database can be added. Use -SharedPath and optionally -MasterKeySecurePassword to enable automatic certificate copying."
417
+
}
418
+
}
419
+
368
420
$progress['Status'] ="Step 2/5: Running backup and restore if needed"
0 commit comments