首页 > 解决方案 > 如何使用 Azure CLI 获取存储帐户的 blob 列表?

问题描述

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

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

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

有人有想法吗?

标签: azureazure-blob-storage

解决方案


更新:在 cli 中获取帐户密钥:

请尝试下面的代码,它可以列出存储帐户的所有容器中的所有 blob。

请注意,“=”周围没有空格。

 # 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

测试结果如下:

在此处输入图像描述


推荐阅读