Script to fetch Azure storage details. The following script can be used to list all the containers of a storage account along with blobs stored in the containers.

Azure CLI can be installed from here.

You need run ‘az login‘ command before running the below script, which is required for the authorization.

The following command can be used to list all the storage accounts of a subscription.

az storage account list --subscription <subscription id> --query "[].{name:name}" --output tsv 

Script to list containers and blobs of a storage account.

 #! /bin/bash  
 account="storage_account"  
 key="$(az storage account keys list -n ${account} --query "[0].{value:value}" --output tsv)"  
 containers=( $(az storage container list --account-name ${account} \  
                --account-key $key --query "[].{name:name}" --output tsv) )  
 for container in "${containers[@]}"; do  
   echo "----------------------------------------------------------------------"  
   echo "container:$container"  
   blobs=( $(az storage blob list --container-name $container \  
              --account-name ${account} \  
              --account-key $key \  
              --query "[].{name:name}" --output tsv) )  
   for blob in "${blobs[@]}"; do   
       echo "blob: $blob"  
   done  
 done  

Leave a Reply

Your email address will not be published. Required fields are marked *

Verified by MonsterInsights