Is there any way to update an encrypted (always encrypted) column with PowerShell or nothing yet? The master key is stored in Azure Key Vault.
I'm able to update a column on a not encrypted column using the PowerShell below:
$sqlConn = New-Object System.Data.SqlClient.SqlConnection
$sqlConn.ConnectionString = "Server=MyServer;Integrated Security=true; Initial Catalog=MyDatabase; Column Encryption Setting=enabled;"
$sqlConn.Open()
$sqlcmd = New-Object System.Data.SqlClient.SqlCommand
$sqlcmd.Connection = $sqlConn
$sqlcmd.CommandText = "UPDATE dbo.MyTable SET Col1 = @col1"
$sqlcmd.Parameters.Add((New-Object Data.SqlClient.SqlParameter("@col1",[Data.SQLDBType]::NVARCHAR, 50)))
$sqlcmd.Parameters["@col1"].Value = "MyNewValue"
$sqlcmd.ExecuteNonQuery()
$sqlConn.Close()
I'm able to update an encrypted column if I connect to Microsoft SQL Server Management Studio, connecting to my database with a user that has access to the master key, stored in Azure Keyvault, if I'm using parametrization (System.Data.SqlClient.SqlParameter
) like this:
DECLARE @myNewValue nvarchar(50) = 'MyNewValue'
UPDATE [dbo].[MyTable]
SET col1 = @myNewValue
Does anyone know how to do it with Powershell?
Thank you!