Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the blob list of storage accounts with Azure CLI?

I'm using Microsoft Azure CLI and I could not find a way to list the blob object of a storage account.

I have the list displayed in Azure Web portal but I don't find any away to do it with the az storage command.

I've tried az storage blob list but it required a container name which I don't know how to find it (with az cli).

Do someone have an idea ?

like image 597
skidrow Avatar asked Mar 21 '19 18:03

skidrow


1 Answers

Update: fetch the account key in cli:

Please try the code below, which can list all the blobs in all the containers of your storage account.

Note that there are no whitespaces aroud "=".

 # list storage account names
 az storage account list --query "[].{name:name}" --output tsv)"

 # update with your storage account name
 storage_account_name="your_storage_account_name"

 key="$(az storage account keys list -n ${storage_account_name} --query "[0].{value:value}" --output tsv)"
    
 containers="$(az storage container list --account-name ${storage_account_name} --account-key $key --query "[].{name:name}" --output tsv)"
    
 for c in $containers
 do
   echo "==== Blobs in Container $c ===="
   az storage blob list --container-name $c \
      --account-name ${storage_account_name} \
      --account-key $key \
      --query "[].{name:name}" --output tsv
 done

Test results as below:

enter image description here

like image 151
Ivan Yang Avatar answered Nov 05 '22 07:11

Ivan Yang