Skip to content

Instantly share code, notes, and snippets.

@mikerodionov
Last active June 9, 2018 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikerodionov/881e02e338365d9016d368ba4e2291ca to your computer and use it in GitHub Desktop.
Save mikerodionov/881e02e338365d9016d368ba4e2291ca to your computer and use it in GitHub Desktop.
# Run Install-Module -Name SqlServer if module is not present on your system
Import-Module SqlServer
# Set up connection and database SMO objects
$password = "<replace with your password>"
$sqlConnectionString = "Data Source=70-473-sql-server.database.windows.net;Initial Catalog=AZ_DB_TEST_BASIC;User ID=Mikhail;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].[Subscribers]
$encryptionChanges += New-SqlColumnEncryptionSettings -ColumnName dbo.Subscribers.CreditCardNumber -EncryptionType Deterministic -EncryptionKey "CEK_Auto1"
Set-SqlColumnEncryption -ColumnEncryptionSettings $encryptionChanges -InputObject $smoDatabase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment