Home > Enterprise >  az cli and powershell problems with values
az cli and powershell problems with values

Time:12-17

i'm trying to update the audit policy on a azure sql server: https://learn.microsoft.com/en-us/cli/azure/sql/server/audit-policy?view=azure-cli-latest#az-sql-server-audit-policy-update

az sql server audit-policy update `
    -g $group -n $sqlServerName --state Enabled --bsts Enabled `
    --storage-endpoint "https://$($storagename).blob.core.windows.net" `
    --storage-key $somekey

now i've tried the key by wrapping in quotes like:

az sql server audit-policy update `
    -g $group -n $sqlServerName --state Enabled --bsts Enabled `
    --storage-endpoint "https://$($storagename).blob.core.windows.net" `
    --storage-key '"'   $somekey   '"'

I know the values work because I typed the whole command out with just the values and it works

az sql server audit-policy update -g somestorage -n somesqlserver --state Enabled --bsts Enabled --storage-endpoint https://somestorageaccount.blob.core.windows.net --storage-key somelongencodedkey==

this is the error (scrubbed of sensitive data):

[DBG]: $error[1].Exception
DEBUG: cli.knack.cli: Command arguments: ['sql', 'server', 'audit-policy', 'update', '-g', 'somegroup', '-n', 'somesqlserver', '--state', 'Enabled',   
'--bsts', 'Enabled', '--storage-endpoint', 'https://somestorageaccount.blob.core.windows.net', '--storage-key',
'somelongkey==', '--debug']

CodePudding user response:

I have reproduced in my environment and got expected results as below and Followed Microsoft-Document:

Firstly, I have used your given command as below:

az sql server audit-policy update `
    -g $group -n $sqlServerName --state Enabled --bsts Enabled `
    --storage-endpoint "https://$($storagename).blob.core.windows.net" `
    --storage-key $somekey

And got error as below:

enter image description here

Thanks to @mklement0 have tried his command as below and got expected results:

$somekey='
cfg'
az sql server audit-policy update `
    -g $group -n $sqlServerName --state Enabled --bsts Enabled `
    --storage-endpoint "https://$($storagename).blob.core.windows.net" `
    --storage-key ('"'   $somekey   '"')

enter image description here

enter image description here

  • Related