Skip to content

Instantly share code, notes, and snippets.

@joshooaj
Created January 12, 2024 01:13
Show Gist options
  • Save joshooaj/bb8f88aa98ca05ee2542d1d232cae269 to your computer and use it in GitHub Desktop.
Save joshooaj/bb8f88aa98ca05ee2542d1d232cae269 to your computer and use it in GitHub Desktop.
List available Milestone XProtect VMS Hotfix downloads
function Get-VmsHotfixes {
[CmdletBinding()]
param(
[Parameter()]
[string]
$Version
)
process {
$ProgressPreference = 'SilentlyContinue'
$Uri = 'https://download.milestonesys.com/MTSKB/hotfixes/'
$baseUri = [UriBuilder]$Uri
if (-not [string]::IsNullOrEmpty($Version)) {
$baseUri.Path = Join-Path $baseUri.Path $Version
}
$stack = [system.collections.generic.stack[uri]]::new()
$stack.Push($baseUri.Uri)
while ($stack.Count) {
try {
$response = Invoke-WebRequest -Uri $stack.Pop() -ErrorAction Stop
foreach ($link in $response.Links) {
if ($link.href -notmatch '^/') {
continue
}
$baseUri.Path = $link.href
if ($link.href -notmatch '\.(exe|msi|zip|txt|config)$') {
$stack.Push($baseUri.Uri)
} elseif ($link.href -match '^/MTSKB/hotfixes/(?<version>[\d\.]+)/(?<component>[^/]+)/') {
if ($Matches.component -match 'archived') {
continue
}
$fileName = ([io.fileinfo]$link.href).Name
$length = 0
$modified = $null
try {
$headReq = Invoke-WebRequest -Uri $baseUri.Uri -Method Head -ErrorAction Stop
$length = [long]$headReq.Headers.'Content-Length'
$modified = $headReq.Headers.'Last-Modified' | Get-Date
} catch {
Write-Error -ErrorRecord $_
}
[pscustomobject]@{
Version = $Matches.version
Component = $Matches.component
File = $fileName
Length = $length
Modified = $modified
Uri = $baseUri.Uri
}
}
}
} catch {
Write-Error -ErrorRecord $_
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment