#PSTip Listing all blobs in a public Azure storage container

In the earlier article, I showed you how to deploy a Azure VM from VM depot. The VM depot has a public storage container where all the VHDs are stored as blobs. I was looking for a way to get a list of all blobs in a public container and had no luck with the Azure PowerShell cmdlets.

I had approached Gaurav–good friend and an Azure MVP–and he showed me a way to do this using Azure Blob Service API. This is a simple and neat trick. The following code snippet shows how this can be done. For this example, we will use the VM depot community blob store URL (https://vmdepoteastus.blob.core.windows.net/linux-community-store/).

$uri = "https://vmdepoteastus.blob.core.windows.net/linux-community-store/?comp=list&restype=container"
$wc = New-Object System.Net.WebClient
$xml = (($wc.DownloadString($uri))).EnumerationResults

$xml.Blobs.Blob | ForEach-Object {
    New-Object -TypeName PSObject -Property @{
        BlobName = $_.Name
        BlobUrl = $_.Url
        BlobType = $_.Properties.BlobType

I tried using Invoke-RestMethod and Invoke-WebRequest. Both are returning invalid XML and therefore I am forced to use .NET WebClient. This is a simple way to explore what is there in an Azure storage container.

Share on: