Event handler for the TDE decryption process in powershell

The code below successfully decrypts, but if the database is huge, it will take some time to decrypt the database

$sqlServer = New-Object ('Microsoft.SqlServer.Management.Smo.Server') $sqlName
$ExistingDB=$sqlServer.Databases.Item($dbname) 
$ExistingDB.EncryptionEnabled=$false
$ExistingDB.Alter()
$ExistingDB.DatabaseEncryptionKey.Refresh()
$ExistingDB.DatabaseEncryptionKey.Drop()

I want to back up after decryption is complete. Is there an event handler to identify the completion of database decryption?

0
source share
1 answer

I do not see anything that emits events in the object model when the encryption / decryption process is running. But you have two options.

  • $ExistingDB.DatabaseEncryptionKey.EncryptionState - this is an enumeration in which it is indicated whether the database is in the process of encryption / decryption, is actually encrypted / decrypted, etc.

  • sys.dm_database_encryption_keys. , , percent_complete, .

+1

Source: https://habr.com/ru/post/1678044/


All Articles