Last active
May 8, 2025 16:36
-
-
Save joshooaj/e07bb5d2d578050f660494575261a67b to your computer and use it in GitHub Desktop.
Gets a list of Milestone downloads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-MilestoneDownloadsList { | |
<# | |
.SYNOPSIS | |
Gets a list of blobs stored at https://milestonedownload.blob.core.windows.net/files | |
.PARAMETER Prefix | |
Specifies an optional blob name prefix like 'Hotfixes', or 'Hotfixes/24.1' | |
.EXAMPLE | |
$blobs = Get-MilestoneDownloadsList -Prefix 'Hotfixes/24.1' | |
#> | |
[CmdletBinding()] | |
param ( | |
[Parameter()] | |
[string] | |
$Prefix | |
) | |
process { | |
Add-Type -AssemblyName System.Web | |
$query = [System.Web.HttpUtility]::ParseQueryString('') | |
$query.Add('restype', 'container') | |
$query.Add('comp', 'list') | |
if ($PSBoundParameters.ContainsKey('Prefix')) { | |
$query.Add('prefix', $Prefix) | |
} | |
$uriBuilder = [uribuilder]::new('https://milestonedownload.blob.core.windows.net/files') | |
$uriBuilder.Query = '' | |
$uriBuilder.Query = $query.ToString() | |
$blobCount = 0 | |
do { | |
$response = Invoke-RestMethod $uriBuilder.Uri | |
$startPostion = $response.IndexOf('<') | |
$xml = [xml]$response.substring($startPostion) | |
if (![string]::IsNullOrEmpty($xml.EnumerationResults.NextMarker)) { | |
# Add or update the marker query parameter with the value of NextMarker if present. | |
$query['marker'] = $xml.EnumerationResults.NextMarker | |
$uriBuilder.Query = $query.ToString() | |
} | |
$blobCount += $xml.EnumerationResults.Blobs.Blob.Count | |
Write-Verbose "Discovered $blobCount blobs" | |
foreach ($blob in $xml.EnumerationResults.Blobs.Blob) { | |
[pscustomobject]@{ | |
Name = $blob.Name | |
Url = $blob.Url | |
Length = $blob.Properties.'Content-Length' | |
LastModified = $blob.Properties.'Last-Modified' | Get-Date | |
ContentType = $blob.Properties.'Content-Type' | |
} | |
} | |
} while (![string]::IsNullOrEmpty($xml.EnumerationResults.NextMarker)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment