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.
- ################# Azure Blob Storage - PowerShell ####################
- ## Input Parameters
- $resourceGroupName="azpractice"
- $storageAccName="azstorageacc1122020"
- ## Connect to Azure Account
- Connect-AzAccount
- ## Function to get all the containers
- Function GetAllStorageContainer
- {
- Write-Host -ForegroundColor Green "Retrieving storage container.."
- ## Get the storage account from which container has to be retrieved
- $storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName
- ## Get the storage account context
- $ctx=$storageAcc.Context
- ## List all the containers
- $containers=Get-AzStorageContainer -Context $ctx
- foreach($container in $containers)
- {
- write-host -ForegroundColor Yellow $container.Name
- }
- }
- GetAllStorageContainer
- ## Disconnect from Azure Account
- 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.

Join the conversation! Your thoughts help the community grow.