Get-AzStorageContainer

This Azure PowerShell article 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 list Azure Storage Containers.

Syntax of Get-AzStorageContainer

Below is the syntax of the Get-AzStorageContainer PowerShell command.

Get-AzStorageContainer
Get-AzStorageContainer
 [[-Name] <String>]

Get-azstoragecontainer example

Let’s discuss a few get-azstoragecontainer examples.

Example-1:

You can run the below PowerShell command to get you the Azure storage container lists.

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 see the same error below

get-azstoragecontainer could not get the storage contex

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 complete PowerShell script below.

$mysARG = "DEMORG2"
$mysAName = "demorg2913f"
$mysAKey = (Get-AzStorageAccountKey -ResourceGroupName $mysARG -AccountName $mysAName).Value[0]
$mystrgctx = New-AzStorageContext -StorageAccountName $mysAName -StorageAccountKey $mysAKey
Get-AzStorageContainer -Context $mystrgctx

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

Get-AzStorageContainer

Example-2:

You can also execute the below PowerShell command to 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

get-azstoragecontainer example

Example-3:

The below script, along with the storage context, will get you the storage container named “azure-web jobs-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

Get-AzStorageContainer PowerShell command

Get-AzStorageContainer PowerShell Command – Video Tutorial

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 !!!