-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Get-MozillaFirefox.ps1
72 lines (63 loc) · 3.13 KB
/
Get-MozillaFirefox.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function Get-MozillaFirefox {
<#
.SYNOPSIS
Returns downloads for the latest Mozilla Firefox releases.
.NOTES
Site: https://stealthpuppy.com
Author: Aaron Parker
Twitter: @stealthpuppy
# https://wiki.mozilla.org/Release_Management/Product_details
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding(SupportsShouldProcess = $false)]
param (
[Parameter(Mandatory = $false, Position = 0)]
[ValidateNotNull()]
[System.Management.Automation.PSObject]
$res = (Get-FunctionResource -AppName ("$($MyInvocation.MyCommand)".Split("-"))[1]),
[Parameter(Mandatory = $false, Position = 1)]
[ValidateNotNull()]
[System.String[]] $Language = @("en-US")
)
# Get latest Firefox version
$Versions = Invoke-EvergreenRestMethod -Uri $res.Get.Update.Uri
# Construct custom object with output details
foreach ($currentLanguage in $Language) {
foreach ($channel in $res.Get.Update.Channels.GetEnumerator()) {
foreach ($platform in $res.Get.Download.Platforms) {
# Select the download file for the selected platform
foreach ($installer in $res.Get.Download.Uri[$channel.Key].GetEnumerator()) {
$params = @{
Uri = (($res.Get.Download.Uri[$channel.Key][$installer.Key] -replace $res.Get.Download.ReplaceText.Platform, $platform) `
-replace $res.Get.Download.ReplaceText.Language, $currentLanguage)
ErrorAction = "SilentlyContinue"
WarningAction = "SilentlyContinue"
}
$Url = Resolve-InvokeWebRequest @params
if ($null -ne $Url) {
# Catch if version is null
if ([System.String]::IsNullOrEmpty($Versions.$($channel.Key))) {
Write-Verbose -Message "$($MyInvocation.MyCommand): No version info for channel: $($channel.Key)."
$Version = "Unknown"
}
else {
$Version = $Versions.$($channel.Key) -replace $res.Get.Download.ReplaceText.Version, ""
Write-Verbose -Message "$($MyInvocation.MyCommand): Found version: $Version."
}
# Build object and output to the pipeline
$PSObject = [PSCustomObject] @{
Version = $Version
Channel = $channel.Value
Language = $currentLanguage
Architecture = Get-Architecture -String $platform
Type = Get-FileType -File $Url
Filename = (Split-Path -Path $Url -Leaf).Replace('%20', ' ')
URI = $Url
}
Write-Output -InputObject $PSObject
}
}
}
}
}
}