Introduction

In this blog, you will see how to get all Azure Storage Accounts using PowerShell.

Prerequisites

Install Azure PowerShell Module to run the script.

PowerShell Script

Open a text file. Copy and paste the below script. Save the file as script.ps1.

  1. ################# Azure Blob Storage - PowerShell ####################
  2. ## Input Parameters
  3. $resourceGroupName="azpractice"
  4. ## Connect to Azure Account
  5. Connect-AzAccount
  6. ## Function to get all the storage accounts
  7. Function GetAllStorageAccount
  8. {
  9. Write-Host -ForegroundColor Green "Retrieving the storage accounts..."
  10. ## Get the list of Storage Accounts
  11. $storageAccColl=Get-AzStorageAccount
  12. foreach($storageAcc in $storageAccColl)
  13. {
  14. write-host -ForegroundColor Yellow $storageAcc.StorageAccountName
  15. }
  16. Write-Host -ForegroundColor Green "Retrieving the storage accounts from specific resource group..."
  17. ## Get the list of Storage Accounts from specific resource group
  18. $storageAccCollRG=Get-AzStorageAccount -ResourceGroupName $resourceGroupName
  19. foreach($storageAcc in $storageAccCollRG)
  20. {
  21. write-host -ForegroundColor Yellow $storageAcc.StorageAccountName
  22. }
  23. }
  24. GetAllStorageAccount
  25. ## Disconnect from Azure Account
  26. Disconnect-AzAccount
Open PowerShell window and navigate to the location where the script file was saved. Run the following command.
.\script.ps1
Result

Summary

Thus, in this blog, you saw how to get all Azure Storage Accounts using PowerShell.