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?
To list the blobs in a storage account, call one of these methods: BlobContainerClient. GetBlobs. BlobContainerClient.
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With