0

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?

James Z
  • 12,209
  • 10
  • 24
  • 44
SQLDoctor
  • 343
  • 7
  • 16

1 Answers1

1

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.

Ben Thul
  • 31,080
  • 4
  • 45
  • 68