Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 996
Matt Fitzmaurice Avatar asked Oct 28 '15 01:10

Matt Fitzmaurice


People also ask

How do I list all blobs in a container?

To list the blobs in a storage account, call one of these methods: BlobContainerClient. GetBlobs. BlobContainerClient.

How do I find Azure blob storage?

In the left navigation page under Data management, select Azure search to select or create a search service. Follow the steps in the wizard to extract and optionally create searchable content from your blobs. The workflow is the Import data wizard. Use Search explorer in the search portal page to query your content.

What is difference between blob and container in Azure?

A container organizes a set of blobs, similar to a directory in a file system. A storage account can include an unlimited number of containers, and a container can store an unlimited number of blobs.


2 Answers

With the new Az module, you need to do the following

Import-Module Az
$azStorageAccountName = "" # Name of your storage account 
$azStorageAccountKey = "" # Access key for your storage account
$azContainerName = "" # Container name to list your blobs
$azResourceGroupName = "" # Resource group name where storage account lives

$connectionContext = (Get-AzStorageAccount -ResourceGroupName $azResourceGroupName -AccountName $azStorageAccountName).Context
# Get a list of containers in a storage account
Get-AzStorageContainer -Name $azContainerName -Context $connectionContext | Select Name
# Get a list of blobs in a container 
Get-AzStorageBlob -Container $azContainerName -Context $connectionContext | Select Name
like image 95
BICube Avatar answered Nov 13 '22 06:11

BICube


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
like image 40
Brendan Green Avatar answered Nov 13 '22 04:11

Brendan Green