Setting up Transparent Data Encryption (TDE)
This recipe shows how you can set up Transparent Data Encryption using PowerShell and SMO.
Getting ready
In this recipe, we will enable
Transparent Data Encryption (TDE) on the TestDB
database. If you don't already have this test database, log in the SQL Server Management Studio and execute the following T-SQL code:
IF DB_ID('TestDB') IS NULL CREATE DATABASE TestDB GO
You must already have a database master key for this TestDB
database. If not, create it using the Creating a database master key recipe.
How to do it...
These are the steps to set up Transparent Data Encryption (TDE) programmatically:
Open the PowerShell console by going to Start | Accessories | Windows PowerShell | Windows PowerShell ISE.
Import the
SQLPS
module, and create a new SMO Server object as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your instance name $instanceName = "KERRIGAN" $server = New-Object -TypeName Microsoft.SqlServer...