Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Setting up Transparent Data Encryption


This recipe shows how you can set up Transparent Data Encryption using PowerShell and SMO.

Getting ready

Transparent Data Encryption (TDE) is supported only in Enterprise, Developer, or Evaluation editions.

In this recipe, we will enable TDE on the TestDB database. If you don't already have this test database, log in to SQL Server Management Studio and execute the following T-SQL code:

IF DB_ID('TestDB') IS NULL
CREATE DATABASE TestDB
GO

You should already have a database master key for this TestDB database. If you don't have one, create it using the Creating a database master key recipe.

How to do it...

These are the steps to set up TDE programmatically:

  1. Open PowerShell ISE as an administrator.

  2. 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 = "localhost"
    
    $server = New-Object -TypeName Microsoft.SqlServer.Management...