Matthias Güntert
Matthias Güntert

Reputation: 4638

How to pass a SAS-token string as literal to the Azure CLI?

The following works in the classic windows command prompt but not when using the PowerShell command prompt:

az storage blob show 
    --container-name <container name> 
    --name training.txt 
    --account-name <account> 
    --sas-token "spr=https&sv=2018-11-09&si=readpolicy&sr=b&sig=<the signature>"

According to about_Quoting_Rules a single-quoted string should be taken literal. However the following still fails with:

The specified resource does not exist. ErrorCode: ResourceNotFound

Der Befehl "sv" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
Der Befehl "si" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
Der Befehl "sr" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
Der Befehl "sig" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

The error about the "specified resource can not be found" is invalid, because I have tried the same command with classic command prompt where it worked.

az storage blob show 
    --container-name <container name> 
    --name training.txt 
    --account-name <account> 
    --sas-token 'spr=https&sv=2018-11-09&si=readpolicy&sr=b&sig=<the signature>'

So how can I pass this SAS-Token-string as a literal to the Azure CLI?


This happend to me with PowerShell Core 6.2.3 64-bit... same applies after updating to PowerShell Core 7.0.0

Upvotes: 1

Views: 1853

Answers (2)

Gaurav Mantri
Gaurav Mantri

Reputation: 136196

I am able to reproduce this error if I enclose SAS Token in single quotes:

az storage blob show 
    --container-name <container name> 
    --name training.txt 
    --account-name <account> 
    --sas-token 'spr=https&sv=2018-11-09&si=readpolicy&sr=b&sig=<the signature>'

However if I enclose SAS Token in double quotes, I am able to fetch blob's properties.

az storage blob show 
    --container-name <container name> 
    --name training.txt 
    --account-name <account> 
    --sas-token "spr=https&sv=2018-11-09&si=readpolicy&sr=b&sig=<the signature>"

UPDATE

I was able to reproduce this issue in PowerShell console with double quotes as well. However if I included --% (which I believe is for stop parsing token) in my command, I was able to make it work.

Can you try something like:

az storage blob show --% --container-name <container name> --name training.txt --account-name <account> --sas-token "spr=https&sv=2018-11-09&si=readpolicy&sr=b&sig=<the signature>"

Upvotes: 3

Sajeetharan
Sajeetharan

Reputation: 222582

Assin the SAS token to a variable and use it,

For ex:

$saskey=az storage container generate-sas -n $Tempcontainer --account-name $storageAccountName --https-only --permissions dlrw --expiry $end 

and then use as

az storage blob show 
    --container-name <container name> 
    --name training.txt 
    --account-name <account> 
    --sas-token $saskey

Upvotes: 0

Related Questions