Power shell Script Generated By SSMS To Encrypt Database

Tarun Bablani 5 Reputation points
2023-07-26T19:11:48.3033333+00:00

I have used SSMS to encrypt database column and have use key Vault to store the encrypted keys. SSMS Wizard give an option to create a Powershell Script which can be used later to do the same encryption.

I have the latest module and also can see the Keyvalut token.

When I trying to run powershell script. It is throwing error on this piece of code.

Set-SqlColumnEncryption -ColumnEncryptionSettings $ces1,$ces2,$ces3,$ces4 -LogFileDirectory .-InputObject $database -KeyVaultAccessToken $keyVaultAccessToken

method not found: 'void microsoft.data.sqlclient.alwaysencrypted.azurekeyvaultprovider.sqlcolumnencryptionazurekeyvaultprovider..ctor(azure.core.tokencredential)

Has anyone encountered this problem.?

Thanks

Azure SQL Database
{count} votes

2 answers

Sort by: Most helpful
  1. Vahid Ghafarpour 23,385 Reputation points Volunteer Moderator
    2023-07-26T21:16:18.7233333+00:00

    Please ensure the Azure Key Vault Provider is Registered using the following command:

    Get-SqlColumnEncryptionAzureKeyVaultProvider
    

    if not, do it:

    Register-SqlColumnEncryptionAzureKeyVaultProvider -ProviderName "AZURE_KEY_VAULT" -AssemblyPath "C:\path\to\Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.dll"
    

  2. SSingh-MSFT 16,371 Reputation points Moderator
    2023-07-28T04:03:02.9933333+00:00

    Hi Tarun Bablani •,

    Welcome to Microsoft Q&A forum.

    We understand that the below answer did not help, and you are getting method not found error in powershell script.

    Could you please ensure Module requirements are version 21+ on PowerShell 5.1; version 22+ on PowerShell 7.x.

    Let us know if this meets.

    Also refer to below posts which might relate to your issue and could be useful:

    https://stackoverflow.com/questions/65245840/net-core-5-0-sql-azure-always-encrypted-managed-identity

    https://learn.microsoft.com/en-us/dotnet/api/microsoft.data.sqlclient.alwaysencrypted.azurekeyvaultprovider.sqlcolumnencryptionazurekeyvaultprovider?view=akvprovider-dotnet-core-3.0

    https://learn.microsoft.com/en-us/answers/questions/452280/sql-server-always-encryption-error

    https://github.com/MicrosoftDocs/sql-docs/blob/live/docs/relational-databases/security/encryption/configure-column-encryption-using-powershell.md

    Let us know what is the result so that we can further investigate. Thanks

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.