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?
I don't see anything that emits events in the object model for when encryption/decryption progress is made. But, you have two options.
the
$ExistingDB.DatabaseEncryptionKey.EncryptionState
is an enum that details whether the database is in transition to being encrypted/decrypted, is actually encrypted/decrypted, etc.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.