Introduction

In this blog, you will see how to get all the containers from a specific Azure Storage Account using PowerShell.
Prerequisites
Install Azure PowerShell Module to run the script.

PowerShell Script

Open Notepad and paste the following script. Save the file as script.ps1.
  1. ################# Azure Blob Storage - PowerShell ####################
  2. ## Input Parameters
  3. $resourceGroupName="azpractice"
  4. $storageAccName="azstorageacc1122020"
  5. ## Connect to Azure Account
  6. Connect-AzAccount
  7. ## Function to get all the containers
  8. Function GetAllStorageContainer
  9. {
  10. Write-Host -ForegroundColor Green "Retrieving storage container.."
  11. ## Get the storage account from which container has to be retrieved
  12. $storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName
  13. ## Get the storage account context
  14. $ctx=$storageAcc.Context
  15. ## List all the containers
  16. $containers=Get-AzStorageContainer -Context $ctx
  17. foreach($container in $containers)
  18. {
  19. write-host -ForegroundColor Yellow $container.Name
  20. }
  21. }
  22. GetAllStorageContainer
  23. ## Disconnect from Azure Account
  24. Disconnect-AzAccount
Open a Windows PowerShell window and navigate to the location where the script file was saved.
Run the following command.
.\script.ps1
Result
All container names will be displayed.
Reference
https://docs.microsoft.com/en-us/powershell/module/az.storage/get-azstoragecontainer?view=azps-3.3.0
Watch here a full video to learn more about Azure Container Instance.

Summary

In this blog, you learned how to get all the containers from a specific Azure Storage Account using PowerShell.