Event handler for TDE decryption process in powershell

150 Views Asked by At

Below code performs the decryption successfully but if the DB is huge it will take sometime to decrypt the DB

$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 perform a backup once the decryption is completed. Is there an event handler for identifying the completion of DB decryption?

1

There are 1 best solutions below

1
On

I don't see anything that emits events in the object model for when encryption/decryption progress is made. But, you have two options.

  1. the $ExistingDB.DatabaseEncryptionKey.EncryptionState is an enum that details whether the database is in transition to being encrypted/decrypted, is actually encrypted/decrypted, etc.

  2. you can look at the sys.dm_database_encryption_keys system view. It has the same encryption state information provided above, but also has a percent_complete column that indicates progress during a transition.