Listing Azure Blobs with PowerShell

Image Description

Daily PowerShell #66

Daily PowerShell Azure

January 8, 2022

quote Discuss this Article

In this post, we’ll look at how to list Azure blobs with PowerShell.

Azure Blob Storage

Blob storage allows you to store files within Azure for a low cost per gigabyte. In this post, we’ll be listing files stored in Azure blob storage using the Web API provided by Azure. We will assume that the container Public access level is set to Container. This ensures that non-authenticated requests will list the files.

Azure Blob URL

To list blobs, you will first need to construct the URL for your storage account and container. The URL will have the format: https://{storageAccount}{container}.

For example, the imsreleases container is where we store our production and nightly builds of Ironman Software products. One of the containers, universal, contains all the releases of our production PowerShell Universal builds. The URL for this container is:

Accessing the Blob from PowerShell

You can access the blob from PowerShell using Invoke-RestMethod. You will need to include the restype and comp query string parameters to return XML string.

Invoke-RestMethod ""

Processing the Blob XML

Once you have accessed the URL, you will need to convert the XML string to objects. You can cast to an [xml] type to do so. You will need to trim off the first three characters.

[xml]$xml = (Invoke-RestMethod "").Substring(3)

Once you have your XML, you can access the blobs within the object.


Name                                                    Url
----                                                    ---

Access Blob Properties

Each blob will have a name, URL and properties. Properties include information such as when the file was last modified and content type.


Last-Modified    : Tue, 05 May 2020 00:05:46 GMT
Etag             : 0x8D7F0880F8A800C
Content-Length   : 106254336
Content-Type     : application/octet-stream
Content-Encoding :
Content-Language :
Content-MD5      :
Cache-Control    :
BlobType         : BlockBlob
LeaseStatus      : unlocked