Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of all storage accounts in Azure? (C#)

I couldn't find anything about how to get all storage accounts, I know it is possible get all blob containers and queues, so Is it possible to get all storage accounts by Azure-Functions?

Or is it possible to generate a unique SAS Token for access all storage Accounts, so I can use on StorageCredentials(string sasToken) ?

like image 789
HudsonPH Avatar asked Nov 30 '25 11:11

HudsonPH


2 Answers

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

Refer to the following code:

var credentials = SdkContext.AzureCredentialsFactory.FromFile(@"D:\azurecred.txt"); 
var azure = Azure       
    .Configure()
    .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
    .Authenticate(credentials)
    .WithDefaultSubscription();
var account = azure.StorageAccounts.List();

You need to set subscription,client,key,tenantId in your credentials file.

like image 109
Joey Cai Avatar answered Dec 02 '25 01:12

Joey Cai


It is possible to get all storage accounts using the StorageManagementClient (you have to install the Microsoft.WindowsAzure.Management.Storage NuGet package).

After you set your authentication and subscription you can call the List() method on the StorageAccounts property. e. g. :

new StorageManagementClient().StorageAccounts.List()

The List Storage Accounts operation lists the storage accounts that are available in the specified subscription.

Source

like image 25
Martin Brandl Avatar answered Dec 01 '25 23:12

Martin Brandl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!