In this Azure PowerShell article, we will discuss the syntax and usage of the Get-AzStorageContainer PowerShell cmdlet along with a few examples.
Get-AzStorageContainer
The Get-AzStorageContainer is an excellent Azure PowerShell cmdlet that can help you to retrieve the lists of Azure storage containers.
Syntax
Below is the syntax of the Get-AzStorageContainer PowerShell command.
Get-AzStorageContainer
Get-AzStorageContainer
[[-Name] <String>]
Let’s discuss a few get-azstoragecontainer examples.
Example-1:
You can run the below PowerShell command that can get you the lists of Azure storage containers.
Get-AzStorageContainer
But, after executing the above command, I got the below error.
“Get-AzStorageContainer : Could not get the storage context. Please pass in a storage
context or set the current storage context.”
You can able to see the same error as below

Now to fix the error “Get-AzStorageContainer: Could not get the storage context”, I had to pass the storage context along with the Get-AzStorageContainer command. So I ran the below complete PowerShell script.
$mysARG = "DEMORG2"
$mysAName = "demorg2913f"
$mysAKey = (Get-AzStorageAccountKey -ResourceGroupName $mysARG -AccountName $mysAName).Value[0]
$mystrgctx = New-AzStorageContext -StorageAccountName $mysAName -StorageAccountKey $mysAKey
Get-AzStorageContainer -Context $mystrgctx
This time after executing the above script, I got the expected output as below.
Storage Account Name: demorg2913f
Name PublicAccess LastModified IsDeleted Ve
rs
io
nI
d
---- ------------ ------------ --------- --
azure-webjobs-hosts Off 1/19/2023 7:14:38 AM +00:00
azure-webjobs-sec... Off 1/19/2023 7:14:44 AM +00:00
You can check out the same output as below

Example-2:
You can also execute the below PowerShell command that can get you the lists of containers whose names start with “azure-webjobs”.
$mysARG = "DEMORG2"
$mysAName = "demorg2913f"
$mysAKey = (Get-AzStorageAccountKey -ResourceGroupName $mysARG -AccountName $mysAName).Value[0]
$mystrgctx = New-AzStorageContext -StorageAccountName $mysAName -StorageAccountKey $mysAKey
Get-AzStorageContainer -Name azure-webjobs* -Context $mystrgctx
After executing the above script, I got the expected output as below

Example-3:
The below script along with the storage context will get you the storage container named “azure-webjobs-hosts”.
Get-AzStorageContainer -Name "azure-webjobs-hosts" -Context $mystrgctx
After executing the above script, I got the below-expected output
Storage Account Name: demorg2913f
Name PublicAccess LastModified IsDeleted Ve
rs
io
nI
d
---- ------------ ------------ --------- --
azure-webjobs-hosts Off 1/19/2023 7:14:38 AM +00:00
You can see the same output below

You can use the Remove-AzStorageContainer PowerShell command to delete an unused storage container.
Wrapping Up
In this article, we discussed the syntax and usage of the Get-AzStorageContainer PowerShell command with examples. Thanks for reading these examples !!!