#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
    }
}

1

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.

About the author: Ravikanth C

Ravikanth is the founder and editor of the PowerShell Magazine. He is also a PowerShell MVP who works at Dell Inc. He blogs at http://www.ravichaganti.com/blog and you can follow him on Twitter @ravikanth.

Related Posts

%d bloggers like this: