Skip to primary content
Skip to secondary content

Coding Stream of Consciousness

by John Humphreys – Random code from my life.

Coding Stream of Consciousness

Main menu

  • Blog Posts
  • About Me
  • Stack Overflow
  • MapR Forum
  • Conferences
  • Contact

Tag Archives: storage-account

Azure CLI – List Only Storage Accounts with Blob Containers Present

Posted on February 23, 2019 by John Humphreys
Reply

I just had to write a script to find all storage accounts with blobs present in a specific subscription in a specific region.

This proved to be non-trivial as the storage account function doesn’t have a region filter, and you have to manually crawl the accounts to see if they’re using blobs.

Here is the fully-working script I came up with, I hope it helps you out!

rm -f accounts_with_blobs.csv

tenant="your-tenant-id"
subscription="your-subscription-name"
region="your-region"

az login --tenant "${tenant}" --subscription "${subscription}"

# Get all subscription + region filtered storage account names.
accounts=$(az storage account list --output table --subscription "${subscription}" | grep "${region}" | awk '{print $5}')

# Filter out accounts with no blob containers.
for account in $accounts
do
    char_count=$(az storage container list --account-name $account | wc -c)
    if [[ $char_count -lt 4 ]];
    then
       echo "$account has no blobs."
    else
       echo "$account has blobs."
       echo "$account" >> accounts_with_blobs.csv
    fi
done

 

Posted in azure, general | Tagged azure, azure-cli, blob, storage-account | Leave a reply

Archives

  • January 2022
  • November 2021
  • September 2021
  • August 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • July 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • September 2018

Meta

  • Register
  • Log in
Blog at WordPress.com.
  • Follow Following
    • Coding Stream of Consciousness
    • Join 34 other followers
    • Already have a WordPress.com account? Log in now.
    • Coding Stream of Consciousness
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar