Created
January 12, 2024 01:13
-
-
Save joshooaj/bb8f88aa98ca05ee2542d1d232cae269 to your computer and use it in GitHub Desktop.
List available Milestone XProtect VMS Hotfix downloads
This file contains 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-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