Skip to content

Instantly share code, notes, and snippets.

@ad-m
Last active August 1, 2017 04:15
Show Gist options
  • Select an option

  • Save ad-m/a9ef8511bb6a757e112c867417902ad0 to your computer and use it in GitHub Desktop.

Select an option

Save ad-m/a9ef8511bb6a757e112c867417902ad0 to your computer and use it in GitHub Desktop.
Azure - report of current Azure Blob Storage capacity
function get_total_size(){
az storage blob list --account-name $1 --container-name $2 --query "sum([].properties.contentLength)";
}
function get_account_list(){
az storage account list --query '[*].name' --output tsv;
}
function get_container_list(){
az storage container list --account-name $1 --query "[].name" --output tsv
}
function storage_stats(){
echo -e "ACCOUNT_NAME\tCONTAINER_NAME\tSIZE\tHUMAN_SIZE";
get_account_list | while read account_name; do
get_container_list "$account_name" | while read container_name; do
SIZE=$(get_total_size "$account_name" "$container_name");
HUMAN=$(numfmt --to=iec-i --suffix=B --format="%.3f" $SIZE)
echo -e "$account_name\t$container_name\t$SIZE\t$HUMAN";
done;
done;
};
storage_stats;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment