Ironman Software Forums
Continue the conversion on the Ironman Software forums. Chat with over 1000 users about PowerShell, PowerShell Universal, and PowerShell Pro Tools.
In this post, we’ll look at how to list Azure blobs with PowerShell.
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.
To list blobs, you will first need to construct the URL for your storage account and container. The URL will have the format:
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:
You can access the blob from PowerShell using
Invoke-RestMethod. You will need to include the
comp query string parameters to return XML string.
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 "https://imsreleases.blob.core.windows.net/universal?restype=container&comp=list").Substring(3)
Once you have your XML, you can access the blobs within the object.
$xml.EnumerationResults.Blobs.Blob <# Name Url ---- --- 83/PowerShellUniversal.1.0.1.msi https://imsreleases.blob.core.windows.net/universal/83/PowerShellUniversal.1.0.1.msi 83/Universal.1.0.1.zip https://imsreleases.blob.core.windows.net/universal/83/Universal.1.0.1.zip logo.png https://imsreleases.blob.core.windows.net/universal/logo.png production/1.0.0/PowerShellUniversal.1.0.0.msi https://imsreleases.blob.core.windows.net/universal/production/1.0.0/PowerShellUniversal.1.0.0.msi #>
Each blob will have a name, URL and properties. Properties include information such as when the file was last modified and content type.
$xml.EnumerationResults.Blobs.Blob.Properties <# 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 #>
Find this useful? Please consider sharing this article. Have a question about PowerShell? Contact us and we'll write a post about it.