How to access storage accounts file share list in automation runbook using PowerShell without endpoint

Shekar Yenagandula 116 Reputation points
2023-01-27T03:08:15.0333333+00:00

I'm having task to get all the storage accounts in the multiple azure subscription to enable backup on file share.Is it possible when public network access disabled on the storage account. I don't want to go with private endpoint solution as I have lot of storage account to backup. Any other ways to get list of storage accounts and their file share without private endpoint and public network access disabled.Appreciate help here

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,714 questions
Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,124 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,081 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 43,951 Reputation points
    2023-02-01T10:56:39.6733333+00:00

    Hello there,

    To get a list of all storage accounts created in Microsoft Azure, run below PowerShell command from a computer where Azure PowerShell cmdlets version 1.0 is installed:

    Get-AzureRmStorageAccount | export-CSV AzureStorageAccounts.CSV

    You could use Microsoft.Azure.Management.Fluent to list all the storage account in your subscription.

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer--

    0 comments No comments

  2. SaiKishor-MSFT 17,196 Reputation points
    2023-02-01T20:58:39.3633333+00:00

    @Shekar Yenagandula I did some testing and see that the below Powershell script is giving output of fileshares for multiple subscriptions.

    Please try the below script and let me know if this helps. This script will work for storage accounts with public network access enabled or disabled. However, if public network access is disabled, you will need to use a service principal or managed identity to authenticate the PowerShell session. You can use the Azure AD PowerShell cmdlets to create a service principal and grant it access to the storage accounts you want to backup. Then, you can use the service principal credentials to sign in to Azure and run the script.

    foreach ($subscription in $subscriptions)                                              
     {Get-AzSubscription -SubscriptionName $subscription.Name | Set-AzContext
     # Get the list of storage accounts
        $storageAccounts = Get-AzStorageAccount
     # Loop through each storage account
         foreach ($storageAccount in $storageAccounts)
         {
    # Get the list of file shares in the storage account
        $fileShares = Get-AzStorageShare -Context $storageAccount.Context
     # Print the storage account name and file share names
       Write-Output "Storage account: $($storageAccount.StorageAccountName)"
        Write-Output "File shares: $($fileShares.Name -join ", ")"
    } 
    }