-
Notifications
You must be signed in to change notification settings - Fork 3
/
encrypt.ps1
25 lines (16 loc) · 1.22 KB
/
encrypt.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Generated by SQL Server Management Studio at 1:24 PM on 2/18/2020
Import-Module SqlServer
# Set up connection and database SMO objects
$password = "<replace with your password>"
$sqlConnectionString = "Data Source=testmetoday.database.windows.net;Initial Catalog=testae;User ID=todayadmin;Password=$password;MultipleActiveResultSets=False;Connect Timeout=30;Encrypt=True;TrustServerCertificate=False;Packet Size=4096;Application Name=`"Microsoft SQL Server Management Studio`""
$smoDatabase = Get-SqlDatabase -ConnectionString $sqlConnectionString
# If your encryption changes involve keys in Azure Key Vault, uncomment one of the lines below in order to authenticate:
# * Prompt for a username and password:
#Add-SqlAzureAuthenticationContext -Interactive
# * Enter a Client ID, Secret, and Tenant ID:
#Add-SqlAzureAuthenticationContext -ClientID '<Client ID>' -Secret '<Secret>' -Tenant '<Tenant ID>'
# Change encryption schema
$encryptionChanges = @()
# Add changes for table [dbo].[Persons]
$encryptionChanges += New-SqlColumnEncryptionSettings -ColumnName dbo.Persons.FirstName -EncryptionType Deterministic -EncryptionKey "CEK_Auto1"
Set-SqlColumnEncryption -ColumnEncryptionSettings $encryptionChanges -InputObject $smoDatabase