How can I list all fileshares and blobs for all storage accounts on all subscriptions that I have?

Joel Pangilinan 35 Reputation points
2023-02-09T17:38:43.8333333+00:00

Hi, I need to know if there is a script or KQL query that will list me all fileshares and blobs on all storage accounts across all subscriptions that I have

Azure Storage
Azure Storage
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,529 questions
{count} vote

Accepted answer
  1. Sina Salam 22,031 Reputation points Volunteer Moderator
    2023-02-10T00:07:56.5266667+00:00

    @Joel Pangilinan

    @Joel Pangilinan Thank you for reaching out to us.

    To list all file shares and blobs for all storage accounts on all subscriptions, you can use the script below. You might need to modify any of them to suite your need.

    To use bash script and one-liner using azure-cli 2.0.79 that might help you get started with iterating over all storage accounts under a single subscription. You can update your Azure-cli if there is a need.

    From a bash script:

    #!/bin/bash
    #get a list of storage accounts
     for account in `az storage account list --query '[].{Name:name}' --output tsv` 
    #iterate over storage accounts
     do 
      echo $account $(az storage share list --account-name $account --output tsv | awk '{print $2}')
    done
    
    

    One liner:

    for account in `az storage account list --query '[].{Name:name}' --output tsv`;  
    do echo $account $(az storage share list --account-name $account --output tsv | awk '{print $2}') ; 
    done
    
    
    

    This should be similar to the output:

    storageaccountname1 <share1> <share2> <share3>

    storageaccountname2 <share1> <share2>

    Also, to get the Azure File Share through PowerShell, you'd better use the Azure PowerShell instead of the Azure CLI, I think the CLI is not suitable for Linux. You can install the Azure PowerShell module and then use the script like this:

    #Get storageaccount names
    $storageAccount = Get-AzStorageAccount
    
    #Now iterate over the storageaccounts
    foreach ($storage in $storageAccount) { 
        if($storage.PrimaryEndpoints.File -ne $null){
            Get-AzRmStorageShare -ResourceGroupName $storage.ResourceGroupName 
            }
    }
    

    Hope this helps! Kindly let us know if the above helpful and solve the issue.

    Cheers.

    Sina

    2 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. SaiKishor-MSFT 17,336 Reputation points
    2023-02-10T23:06:24.17+00:00

    @Joel Pangilinan Please refer to this similar thread for the script- https://learn.microsoft.com/en-us/answers/questions/1164687/how-to-access-storage-accounts-file-share-list-in

    If you still have any further questions, please let me know. Thank you!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.