Public/Get-FoxitReader.ps1

Function Get-FoxitReader {
    <#
        .SYNOPSIS
            Get the current version and download URL for Foxit Reader.
 
        .NOTES
            Site: https://stealthpuppy.com
            Author: Aaron Parker
            Twitter: @stealthpuppy
         
        .LINK
            https://github.com/aaronparker/Evergreen
 
        .EXAMPLE
            Get-FoxitReader
 
            Description:
            Returns the current version and download URL for Foxit Reader.
    #>

    [OutputType([System.Management.Automation.PSObject])]
    [CmdletBinding()]
    Param()

    # Get application resource strings from its manifest
    $res = Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1]
    Write-Verbose -Message $res.Name

    #region Get Foxit Reader details
    # Query the Foxit Reader package download form to get the JSON
    $Content = Invoke-WebContent -Uri $res.Get.Uri
    If ($Null -ne $Content) {

        # Convert JSON
        try {
            $PackageJson = $Content | ConvertFrom-Json
        }
        catch [System.Exception] {
            Write-Warning -Message "$($MyInvocation.MyCommand): failed to convert to JSON."
            Break
        }

        # Grab latest version
        $Version = ($PackageJson.package_info.version | Sort-Object { [Version]$_ } -Descending) | Select-Object -First 1

        ForEach ($language in $PackageJson.package_info.language) {
            
            # Build the download URL
            $Uri = (($res.Get.DownloadUri -replace "#Version", $Version) -replace "#Language", $language) -replace "#Package", $PackageJson.package_info.type[0]
            
            # Follow the download link which will return a 301/302
            $redirectUrl = Resolve-RedirectedUri -Uri $Uri
            
            # Construct the output; Return the custom object to the pipeline
            If ($Null -ne $redirectUrl) {
                $PSObject = [PSCustomObject] @{
                    Version  = $Version
                    Date     = ConvertTo-DateTime -DateTime $PackageJson.package_info.release -Pattern $res.Get.DateTimePattern
                    Language = $language
                    URI      = $redirectUrl
                }
                Write-Output -InputObject $PSObject
            }
            Else {
                Write-Warning -Message "Failed to return a useable URL from $Uri."
            }
        }
    }
    Else {
        Write-Warning -Message "$($MyInvocation.MyCommand): unable to retreive content from $($res.Get.Uri)."
    }
    #endregion
}