SQL Server 2016 - 始终加密 - 缺少生成Powershell的选项

时间:2017-10-09 01:19:38

标签: sql-server powershell ssms sql-server-2016 always-encrypted

我目前正在测试SQL Server 2016的Always Encrypted功能,我能够使用默认密钥对列进行加密,但我无法通过“生成PowerShell脚本以便稍后运行”选项来编写此脚本。

enter image description here

有没有人遇到并重新调解过这个?

1 个答案:

答案 0 :(得分:2)

它在我的环境中工作:

enter image description here

我认为我有类似的问题,因为我没有使用最新的SQL Server Management Studio。您可以找到最新版本here

生成的代码看起来像这样 - 我想你可以改变它并尝试如果你不能保存为PS脚本:

# Generated by SQL Server Management Studio at 9:15 AM on 2017-10-09

Import-Module SqlServer
# Set up connection and database SMO objects

$sqlConnectionString = "Data Source=SQLInstanceName\INST1;Initial Catalog=databaseName;Integrated Security=True;MultipleActiveResultSets=False;Connect Timeout=30;Encrypt=False;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].[TablenameX]
$encryptionChanges += New-SqlColumnEncryptionSettings -ColumnName dbo.TablenameX.columNameX -EncryptionType Deterministic -EncryptionKey "CEK_Auto1"

Set-SqlColumnEncryption -ColumnEncryptionSettings $encryptionChanges -InputObject $smoDatabase

SQL版本是:

  

Microsoft SQL Server 2016(SP1)(KB3182545) - 13.0.4001.0(X64)10月   28 2016 18:17:30版权所有(c)Microsoft Corporation Enterprise   版本:Windows Server 2012 R2上基于Core的许可(64位)   标准6.3(Build 9600:)(管理程序)

SSMS版本为Microsoft SQL Server Management Studio 14.0.17177.0 - 或来自我提供的链接的v17.2。