PowerShell-查找最新版本的Firefox


0

我想知道是否可以使用PowerShell找到最新版本的Firefox(稳定版)?

我只想获取纯文本的最新版本号,不需要链接或Beta版本等。


1
那是已安装的还是一般可用的?可能有一种编写脚本来完成此操作的方法。
赛斯

最新的可用版本将用于自动检查已安装的版本。
TommyBråthen'17

这是一个主意:使用PowerShell打开ftp.mozilla.org/pub/firefox/releases,将其作为输出文本文件,删除包含“ b”字母的版本以删除beta版本并检查最高编号。
Biswapriyo

Answers:


1

PS版本3及更高版本的解决方案

$ff = Invoke-WebRequest  "*https://product-details.mozilla.org/1.0/firefox_versions.json*" | ConvertFrom-Json
$ff.psobject.properties.value[-1]

最新版本可以在https://product-details.mozilla.org/1.0/firefox_versions.json中找到

这包含

{
  "FIREFOX_NIGHTLY": "56.0a1",
  "FIREFOX_AURORA": "54.0a2",
  "FIREFOX_ESR": "52.2.1esr",
  "FIREFOX_ESR_NEXT": "",
  "LATEST_FIREFOX_DEVEL_VERSION": "55.0b8",
  "LATEST_FIREFOX_OLDER_VERSION": "3.6.28",
  "LATEST_FIREFOX_RELEASED_DEVEL_VERSION": "55.0b8",
  "LATEST_FIREFOX_VERSION": "54.0.1"
}

Invoke-WebRequest cmdlet发送HTTPS请求以返回Json文件,该文件需要从JavaScript Object Notation(JSON)格式的字符串转换为自定义PSCustomObject。

Json具有“名称”字段和“值”字段,最后一行包含LATEST_FIREFOX_VERSION和54.0.1

您想要版本号。(值)作为其最后一行,您可以使用[-1]请求PowerShell数组中的最后一个元素

第一行使用[0],每夜56.0a1,下一行增加。或从[-1]减至[-2],即倒数第二行


1

我正在使用以下脚本将在线可用的最新版本与安装的Firefox版本(对于SCCM应用程序类型检测规则)进行比较:

    $FFInstalled = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Mozilla\Mozilla Firefox' | Select 'CurrentVersion').CurrentVersion
    $FFLatest = ( Invoke-WebRequest  "https://product-details.mozilla.org/1.0/firefox_versions.json" -UseBasicParsing | ConvertFrom-Json ).LATEST_FIREFOX_VERSION
    If ($FFInstalled -match $FFLatest) {$true} Else {$null}

如果这些版本匹配,则返回True,否则返回True,否则返回Error(如果该注册表项不存在)。

要简短地回答您的版本,您可以使用代码的第二行以获取最新的在线信息。


0

我一直在研究一些PowerShell脚本,以从我使用其第三方产品的供应商网站中提取版本信息。我以前使用FileHippo作为中心点创建了这样的脚本,但是我想尝试一些更具挑战性的事情。

这将为您提供Firefox的当前版本,发行日期和每种体系结构的直接URL。如果有帮助,请务必使用其中的任何一块或一部分。

function Get-OnlineVerFirefox
{

    [cmdletbinding()]
    param (
        [Parameter(Mandatory=$false, 
                   Position=0)]
        [switch]
        $Quiet
    )

    begin
    {
        # Initial Variables
        $SoftwareName = "Mozilla Firefox"
        $uri = 'https://product-details.mozilla.org/1.0/firefox_versions.json'


        $hashtable = [ordered]@{
            'Software_Name'    = $softwareName
            'Software_URL'     = $uri
            'Online_Version'   = 'UNKNOWN' 
            'Online_Date'      = 'UNKNOWN'
            'Download_URL_x64' = 'UNKNOWN'
            'Download_URL_x86' = 'UNKNOWN'

        }

        $swObject = New-Object -TypeName PSObject -Property $hashtable
    }


   Process
    {
        # Get the Version & Release Date
        try
        {
            Write-Verbose -Message "Attempting to pull info from the below URL: `n $URI"


        $uri = 'https://product-details.mozilla.org/1.0/firefox_versions.json'
        $FirefoxVersion = Invoke-WebRequest $uri -UseBasicParsing | ConvertFrom-Json | select -ExpandProperty LATEST_FIREFOX_vERSION
        $FirefoxDate = (Invoke-WebRequest 'https://product-details.mozilla.org/1.0/firefox_history_stability_releases.json' -UseBasicParsing | ConvertFrom-Json) | select -ExpandProperty $FirefoxVersion
        $FirefoxDownloadX64 = "https://download-origin.cdn.mozilla.net/pub/firefox/releases/" + $FirefoxVersion + "/win64/en-US/Firefox%20Setup%20" + $FirefoxVersion + ".exe"
        $FirefoxDownloadX86 = "https://download-origin.cdn.mozilla.net/pub/firefox/releases/" + $FirefoxVersion + "/win32/en-US/Firefox%20Setup%20" + $FirefoxVersion + ".exe"


        $swObject.Online_Version = $FirefoxVersion
        $swobject.Online_Date = $FirefoxDate



        } 
        catch
        {
            Write-Verbose -Message "Error accessing the below URL: `n $URI"
            $message = $("Line {0} : {1}" -f $_.InvocationInfo.ScriptLineNumber, $_.exception.message)
            $swObject | Add-Member -MemberType NoteProperty -Name 'ERROR' -Value $message
        }
        finally
        {


        # Get the Download URLs
        if ($swObject.Online_Version -ne 'UNKNOWN')
        {

            $swobject.Download_URL_X64 = $FirefoxDownloadX64
            $swobject.Download_URL_X86 = $FirefoxDownloadX86
        }
  }
    }
    End
    {
        # Output to Host
        if ($Quiet)
        {
            Write-Verbose -Message '$Quiet was specified. Returning just the version'
            Return $swObject.Online_Version
        }
        else
        {
            Return $swobject
        }
    }
}  # END Function Get-OnlineVerFirefox

这是输出示例。您可以将输出的一部分作为直通变量等。

PS C:\> Get-OnlineVerFirefox.ps1

Software_Name    : Mozilla Firefox
Software_URL     : https://product-details.mozilla.org/1.0/firefox_versions.json
Online_Version   : 61.0.2
Online_Date      : 2018-08-08
Download_URL_x64 : https://download-origin.cdn.mozilla.net/pub/firefox/releases/61.0.2/win64/en-US/Firefox%20Setup%2061.0.2.exe
Download_URL_x86 : https://download-origin.cdn.mozilla.net/pub/firefox/releases/61.0.2/win32/en-US/Firefox%20Setup%2061.0.2.exe

PS C:\> Get-OnlineVerFirefox -Quiet
61.0.2
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.