如何使用 Azure CLI 获取存储帐户的 blob 列表?

ski*_*row 5 azure azure-storage-blobs

我正在使用 Microsoft Azure CLI,但找不到列出存储帐户的 blob 对象的方法。

我在 Azure Web 门户中显示了该列表,但我找不到任何可以使用该az storage命令执行此操作的方法。

我试过了,az storage blob list但它需要一个容器名称,我不知道如何找到它(使用 az cli)。

有人有想法吗?

Iva*_*ang 9

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
Run Code Online (Sandbox Code Playgroud)

Test results as below:

在此处输入图片说明