Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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
You can’t perform that action at this time.