Private/GetMUCatalogUpdateInfo.ps1

function GetMUCatalogUpdateInfo {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [string]
        $Uri
    )

    $updateInfo = @{
        "UpdateID" = ""
        "Files" = New-Object -TypeName "System.Collections.ArrayList"
    }

    # https://www.catalog.update.microsoft.com/ScopedViewInline.aspx?updateid={{UPDATE_GUID}}
    if ($Uri -match "updateid=([a-zA-Z\d]{8}-([a-zA-Z\d]{4}-){3}[a-zA-Z\d]{12})") {
        Write-Verbose "Found update ID in URI ($( $Matches[1] ))."
    } else {
        $webRequestParams = GetWebRequestSplatBase -Uri $Uri
        $updateInfoResponse = Invoke-WebRequest @webRequestParams -ErrorAction Stop

        if ($updateInfoResponse.Content -notmatch '"ScopedViewHandler_UpdateID">([a-zA-Z\d]{8}-([a-zA-Z\d]{4}-){3}[a-zA-Z\d]{12})</') {
            Write-Error -Message "Could not parse update ID from response." `
                -Category "ObjectNotFound" `
                -ErrorId "CouldNotParseUpdateID"
            return
        }
    }

    $updateInfo["UpdateId"] = $Matches[1]
    $updateFilesRequestParams = @{
        "updateIDs" = "[{`"size`":0,`"languages`":`"`",`"uidInfo`":`"$( $updateInfo["UpdateId"] )`",`"updateID`":`"$( $updateInfo["UpdateId"] )`"}]"
    }
    $webRequestParams = GetWebRequestSplatBase -Uri "https://www.catalog.update.microsoft.com/DownloadDialog.aspx"
    $webRequestParams["Method"] = "Post"
    $webRequestParams["Body"] = $updateFilesRequestParams
    $updateFilesResponse = Invoke-WebRequest @webRequestParams -ErrorAction Stop

    if ($updateFilesResponse.Content -notmatch "downloadInformation = ([\s\S]+?)minFilePath") {
        Write-Error -Message "Could not parse download information from response." `
            -Category "ObjectNotFound" `
            -ErrorId "CouldNotParseDownloadInformation"
        return
    }

    $fileInfoMatches = [regex]::Matches(
        $Matches[1],
        "files\[\d\] = new Obj[\s\S]+?url = '(.*?)';[\s\S]+?fileName = '(.*?)';[\s\S]+?defaultFile",
        [System.Text.RegularExpressions.RegexOptions]"IgnoreCase,Multiline",
        [timespan]::FromSeconds(60)
    )

    if ($fileInfoMatches.Count -eq 0) {
        Write-Error -Message "Could not parse file list from response." `
            -Category ObjectNotFound `
            -ErrorId "CouldNotParseFileList"
        return
    }

    foreach ($fileInfoMatch in $fileInfoMatches) {
        [void]($updateInfo["Files"].Add(@{
            "Uri" = $fileInfoMatch.Groups[1].Value
            "FileName" = $fileInfoMatch.Groups[2].Value
        }))
    }

    return $updateInfo
}

# Copyright (c) 2023 AJ Tek Corporation. All Rights Reserved.