Search code examples
azurepowershellazure-keyvaultazure-cli

Azure cli, "az keyvault secret set" to set localDB connection string errors in powershell due to Parenthesis (localDB)


In powershell,

Using az keyvault secret set to set the localdb connection string as a key vault secret fails because of the closing parenthesis ")" that precedes the "\\".

az keyvault secret set --name ConnectionString-messaging --vault-name kvtemptest --value "server=(LocalDb)\\MSSQLLocalDb;database=messaging;trusted_connection=yes;Pooling=false;"

the error I get is

\MSSQLLocalDb was unexpected at this time.

Tried the below too

(backtick) but same results az keyvault secret set --name ConnectionString-bwalk-messaging --vault-name kvsamtemptest --value "server=(LocalDb)\MSSQLLocalDb;database=Bwalk_Messaging;trusted_connection=yes;Pooling=false;" `

(doubling the braces) az keyvault secret set --name ConnectionString-bwalk-messaging --vault-name kvsamtemptest --value "server=((LocalDb))\MSSQLLocalDb;database=Bwalk_Messaging;trusted_connection=yes;Pooling=false;"`

the command works gr8 in git bash console


Solution

  • az --% az keyvault secret set --name ConnectionString-messaging --vault-name kvtemptest --value "server=(LocalDb)\\MSSQLLocalDb;database=messaging;trusted_connection=yes;Pooling=false;" should work.

    That is mentioned here: https://learn.microsoft.com/en-us/cli/azure/use-cli-effectively?tabs=powershell%2Cpowershell2#use-quotation-marks-in-parameters and powershell documentation here: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing?view=powershell-7.3#the-stop-parsing-token