Search code examples
powershellazureazure-storage

How to list Azure Storage Containers and Blobs


I'm new to Azure Storage and I think I may be misunderstanding a few of the concepts.

I'd like to list all my Storage Containers and Blobs using PowerShell.

I can list all my Storage Accounts using the following code:

Get-AzureStorageAccount | Select StorageAccountName, GeoPrimaryLocation

Each of the Storage Accounts has a Container. How do I get it? I don't see a command that lists Containers. There is a Get-AzureStorageContainer command, but it doesn't take a Storage Account as input.

What am I missing?

-- Edit --

I see that I can do the following:

$context = New-AzureStorageContext -StorageAccountName myStorageAccount -StorageAccountKey xxx
Get-AzureStorageContainer -Context $context
Get-AzureStorageBlob -Context $context -Container myContainer

Why is the context required?


Solution

  • Not sure if this is what you want, but I am able to list containers using New-AzureStorageContext and Get-AzureStorageContainers.

    $ctx = New-AzureStorageContext -StorageAccountName <name> -StorageAccountKey <key>
    
    Get-AzureStorageContainer -Context $ctx