---
title: "Enable-DbaDbEncryption"
description: "Enables Transparent Data Encryption (TDE) on SQL Server databases"
url: "https://dbatools.io/Enable-DbaDbEncryption/"
availability: "Windows, Linux, macOS"
tags: ["Certificate", "Security"]
author: "Chrissy LeMaire (@cl), netnerds.net"
source: "https://github.com/dataplat/dbatools/blob/master/public/Enable-DbaDbEncryption.ps1"
last_updated: "2024-01-01"
---

# Enable-DbaDbEncryption

## Synopsis

Enables Transparent Data Encryption (TDE) on SQL Server databases

## Description

Enables Transparent Data Encryption (TDE) on specified databases to protect data at rest. This is essential for compliance with regulations like HIPAA, PCI-DSS, and organizational security policies. The function automatically creates a Database Encryption Key (DEK) if one doesn't exist, using a certificate from the master database to encrypt it. By default, it verifies that the certificate has been backed up before proceeding, helping prevent data loss scenarios.

## Syntax

```powershell
Enable-DbaDbEncryption
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-Database] <String[]>]
    [[-EncryptorName] <String>]
    [[-InputObject] <Database[]>]
    [-Force]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

```

## Examples

### Example 1: Enables database encryption on the pubs database on sql2017 and sql2016

```powershell
PS C:\> Enable-DbaDbEncryption -SqlInstance sql2017, sql2016 -Database pubs
```

### Example 2: Suppresses all prompts to enable database encryption on the db1 database on sql2017

```powershell
PS C:\> Enable-DbaDbEncryption -SqlInstance sql2017 -Database db1 -Confirm:$false
```

### Example 3: Suppresses all prompts to enable database encryption on the db1 database on sql2017

```powershell
PS C:\> Get-DbaDatabase -SqlInstance sql2017 -Database db1 | Enable-DbaDbEncryption -Confirm:$false
```

### Optional Parameters

##### -SqlInstance

The target SQL Server instance or instances.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -SqlCredential

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).  
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.  
For MFA support, please use Connect-DbaInstance.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Database

Specifies which databases to enable Transparent Data Encryption (TDE) on. Accepts multiple database names.  
Use this when you need to enable encryption on specific databases rather than all databases on the instance.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -EncryptorName

Specifies the certificate name in the master database to use for encrypting the Database Encryption Key (DEK).  
If not specified, the function will attempt to find an existing certificate. Use this when you have multiple certificates and need to specify which one to use for TDE.  
The certificate must exist in the master database and should be backed up to prevent data loss.

| Property | Value |
| --- | --- |
| Alias | Certificate,CertificateName |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -InputObject

Accepts database objects from Get-DbaDatabase through the pipeline.  
Use this when you want to filter databases first with Get-DbaDatabase and then enable TDE on the results.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | true (ByValue) |
| Default Value |  |

##### -Force

Bypasses the certificate backup verification check and enables TDE even if the certificate hasn't been backed up.  
Use with extreme caution as this could lead to data loss if the certificate is lost without a backup.  
Only use this in development environments or when you have confirmed the certificate is backed up through other means.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -EnableException

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.  
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.  
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

| Property | Value |
| --- | --- |
| Alias | wi |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Confirm

Prompts you for confirmation before executing any changing operations within the command.

| Property | Value |
| --- | --- |
| Alias | cf |
| Required | False |
| Pipeline | false |
| Default Value |  |

## Outputs

**Microsoft.SqlServer.Management.Smo.Database**

Returns one Database object per database where encryption was enabled successfully.

**Default display properties (via Select-DefaultView):**

- ComputerName: The computer name of the SQL Server instance
- InstanceName: The SQL Server instance name
- SqlInstance: The full SQL Server instance name (computer\instance)
- DatabaseName: The name of the database where encryption was enabled (Name property aliased)
- EncryptionEnabled: Boolean indicating whether Transparent Data Encryption is now enabled on the database

**Additional properties available (from SMO Database object):**

- CreateDate: DateTime when the database was created
- LastBackupDate: DateTime of the last database backup
- Owner: Database owner/principal name
- RecoveryModel: Database recovery model (Simple, Full, BulkLogged)
- Status: Current database status
- Size: Database size in megabytes
- DatabaseEncryptionKey: The Database Encryption Key object containing encryption details
- EncryptionAlgorithm: The algorithm used for encryption (AES_128, AES_192, AES_256)
All properties from the base SMO Database object are accessible even though only default properties are displayed without using Select-Object *.

---

Part of [dbatools](https://dbatools.io/), a free and open source PowerShell module for SQL Server administration. Full command index: https://dbatools.io/commands/
