How to disable database encryption through powershell

I have a database that is encrypted in TDE. Now I need to disable this encryption through PowerShell. I can get some breakthrough, but when faced with the error below

Error: Cannot delete the database encryption key because it is currently in use. Database encryption must be disabled to remove the database encryption key. however, the encryption key is disabled, but it seems the key is falling. Below is a screenshot of what it looks like after the first code run.

enter image description here

Below  is the code that I have written/used:

   function set-EncryptionOff($ExistingDB)
{
    $ExistingDB.EncryptionEnabled=$false
    $ExistingDB.Alter();
    $ExistingDB.DatabaseEncryptionKey.Refresh()
    $ExistingDB.DatabaseEncryptionKey.Drop()

}
+4
source share
2 answers

. , EncryptionEnabled false, $ExistingDB.Alter(), . , , .

script:

$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() #should work now
+3

, Azure PowerShell Set-AzureRMSqlDatabaseTransparentDataEncryption :

TDE SQL PowerShell

Azure PowerShell, , / TDE. PS . ServerName, ResourceGroupName DatabaseName. PowerShell, . Azure PowerShell.

..

TDE:

Set-AzureRMSqlDatabaseTransparentDataEncryption -ServerName "myserver" -ResourceGroupName "Default-SQL-WestUS" -DatabaseName

"database1" -State "Disabled"

0.9.8, Set-AzureSqlDatabaseTransparentDataEncryption.

: https://docs.microsoft.com/en-us/sql/relational-databases/security/encryption/transparent-data-encryption-with-azure-sql-database

+2

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


All Articles