How to get the blob list of storage accounts with Azure CLI?
Solution 1
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:
Solution 2
Command to get list of containers in a storage account on basis of storage ACCOUNT_NAME and ACCESS_KEY:
az storage container list --account-key ACCESS_KEY --account-name ACCOUNT_NAME
On basis of Container names received in its response, you can use az storage blob list
command to get the list of objects within that container.
Related videos on Youtube
skidrow
Updated on June 04, 2022Comments
-
skidrow almost 2 years
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 ?
-
skidrow about 5 yearsThank you for your answer but how I get my storage account key in my program ? When I want to list the key I have the following error. However,
-
Ivan Yang about 5 years@skidrow, why not get the key directly from the azure portal? and which error are your getting?
-
Ivan Yang about 5 years@skidrow, I updated the code, which get storage account key in cli code. And works fine at my side.
-
skidrow about 5 yearsI got the following error when I want to list my account storage key with
az cli
:The client '[email protected]' with object id '091bb6b2-XXX-46da-ac31-f350XXXXXX' does not have authorization to perform action 'Microsoft.Storage/storageAccounts/listKeys/action' over scope ...
. I understand I have no permission to do so but within the web portal, my user account is able to list the blob object of any storage account (All resources => <storage_account_name> => Objets blob). Is this no possible withaz cli
to get this list (without the account storage key) ? -
Ivan Yang about 5 years@skidrow, yes, without key, it's impossible :(.
-
Pine Code about 4 years
containers=$(az storage container list --connection-string '...')
generates this error:is not recognized as the name of a cmdlet, function, script file, or operable program
. Any help? -
Ivan Yang about 4 years@FrancoScarpa, can you please raise an new issue with more details, and then post the link here?
-
Pine Code about 4 years@IvanYang here or on GitHub?
-
Ivan Yang about 4 years@FrancoScarpa, here stackoverflow:)
-
Pine Code about 4 years@IvanYang: stackoverflow.com/questions/60449605/…
-
Wojciech Kałuski over 3 yearsInstead of account key you can use
--auth-mode login
i.e.az storage container list --auth-mode login --account-name youraccountname
. But you need to set appropriate role to your user first.