Last active
November 5, 2024 07:02
-
-
Save eddiezato/90d3a5ec5c7eeadd94bd65446551da6b to your computer and use it in GitHub Desktop.
PowerShell [5.1+]: script to get Microsoft Edge Offline Installers (can be extracted with 7zip)
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
# params | |
[CmdletBinding(DefaultParameterSetName="Casual")] | |
param ( | |
[Alias("c")] | |
[Parameter(ParameterSetName = "Pro", Mandatory = $true)] | |
[ValidateSet("stable", "beta", "dev", "canary")] | |
[string]$Channel, | |
[Alias("v")] | |
[Parameter(ParameterSetName = "Pro", Mandatory = $true)] | |
[ValidateNotNullOrEmpty()] | |
[string]$Version, | |
[Alias("a")] | |
[Parameter(ParameterSetName = "Pro")] | |
[ValidateSet("x64", "x86")] | |
[string]$Architecture = "x64", | |
[Alias("d")] | |
[Parameter(ParameterSetName = "Pro")] | |
[switch]$Download = $false, | |
[Alias("x")] | |
[switch]$Extract = $false | |
) | |
function Get-Out { | |
[CmdletBinding()] | |
param ( [Parameter(Mandatory = $true)][string]$Message ) | |
Write-Host $Message -ForegroundColor Red | |
exit 1 | |
} | |
# run gui for default check | |
if ($PSCmdlet.ParameterSetName -eq "Casual") { | |
# get versions | |
$Response = $null | |
try { $Response = Invoke-RestMethod -Method Get -Uri "https://edgeupdates.microsoft.com/api/products" } | |
catch { Get-Out -Message "Can't check Edge versions. Try again." -ExitCode 1 } | |
# store versions | |
$verlist = @() | |
if ($Response) { | |
foreach ($ver in ($Response | where { $_.Product.ToLower() -in @("stable", "beta", "dev", "canary") })) { | |
$item = $ver.Releases | where { ($_.Platform.ToLower() -eq "windows") -and ($_.Architecture.ToLower() -eq $Architecture) } | |
$verlist += [PSCustomObject]@{ | |
Channel = $ver.Product.ToString().ToLower() | |
Version = $item.ProductVersion.ToString() | |
Published = (Get-Date -Date $item.PublishedTime).ToString("yyyy.MM.dd HH:mm") | |
} | |
} | |
if (-not $verlist) { Get-Out -Message "Can't check Edge versions (no data). Try again." } | |
} else { Get-Out -Message "Can't check Edge versions (bad response). Try again." } | |
# draw gui | |
Clear-Host | |
Write-Host "Arrows" -NoNewLine -ForegroundColor Cyan; Write-Host " to navigate, " -NoNewLine | |
Write-Host "Enter" -NoNewLine -ForegroundColor Cyan; Write-Host " to download, " -NoNewLine | |
Write-Host "Esc" -NoNewLine -ForegroundColor Cyan; Write-Host " to exit" | |
Write-Host "`n Channel Version Published`n ------- ------- ---------" -ForegroundColor DarkGray | |
foreach ($ver in $verlist) { " {0} {1} {2}" -f $ver.Channel.PadRight(9, " "), $ver.Version.PadRight(14, " "), $ver.Published } | |
Write-Host | |
[Console]::CursorVisible = $false | |
$fcolor = $Host.UI.RawUI.ForegroundColor | |
$bcolor = $Host.UI.RawUI.BackgroundColor | |
$curpos = 0 | |
$Host.UI.RawUI.CursorPosition = @{ X = 0; Y = $curpos + 4 } | |
Write-Host (" {0}" -f $verlist[$curpos].Channel.PadRight(9, " ")) -NoNewLine -ForegroundColor $bcolor -BackgroundColor $fcolor | |
# run navigation | |
$Host.UI.RawUI.FlushInputBuffer(); | |
$navflag = $true | |
do { | |
$key = $Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown") | |
switch ($key.VirtualKeyCode) { | |
38 { | |
if ($curpos -gt 0) { | |
$Host.UI.RawUI.CursorPosition = @{ X = 0; Y = $curpos + 4 } | |
Write-Host (" {0}" -f $verlist[$curpos].Channel.PadRight(9, " ")) -NoNewLine -ForegroundColor $fcolor -BackgroundColor $bcolor | |
$curpos-- | |
$Host.UI.RawUI.CursorPosition = @{ X = 0; Y = $curpos + 4 } | |
Write-Host (" {0}" -f $verlist[$curpos].Channel.PadRight(9, " ")) -NoNewLine -ForegroundColor $bcolor -BackgroundColor $fcolor | |
} | |
break | |
} | |
40 { | |
if ($curpos -lt $verlist.Count - 1 ) { | |
$Host.UI.RawUI.CursorPosition = @{ X = 0; Y = $curpos + 4 } | |
Write-Host (" {0}" -f $verlist[$curpos].Channel.PadRight(9, " ")) -NoNewLine -ForegroundColor $fcolor -BackgroundColor $bcolor | |
$curpos++ | |
$Host.UI.RawUI.CursorPosition = @{ X = 0; Y = $curpos + 4 } | |
Write-Host (" {0}" -f $verlist[$curpos].Channel.PadRight(9, " ")) -NoNewLine -ForegroundColor $bcolor -BackgroundColor $fcolor | |
} | |
break | |
} | |
67 { | |
Set-Clipboard ("{0} -c {1} -v {2}" -f (Get-Item -Path $PSCommandPath).BaseName, $verlist[$curpos].Channel, $verlist[$curpos].Version) | |
$Host.UI.RawUI.CursorPosition = @{ X = 0; Y = $curpos + 4 } | |
Write-Host (" {0}" -f $verlist[$curpos].Channel.PadRight(9, " ")) -NoNewLine -ForegroundColor $bcolor -BackgroundColor Yellow | |
break | |
} | |
13 { | |
# run architecture navigation | |
$Host.UI.RawUI.CursorPosition = @{ X = 0; Y = $curpos + 4 } | |
Write-Host " x64 " -NoNewLine -ForegroundColor $bcolor -BackgroundColor $fcolor | |
Write-Host " x86 " -NoNewLine -ForegroundColor $fcolor -BackgroundColor $bcolor | |
$Architecture = "x64" | |
$Host.UI.RawUI.FlushInputBuffer(); | |
$nav2flag = $true | |
do { | |
$key = $Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown") | |
switch ($key.VirtualKeyCode) { | |
37 { | |
if ($Architecture -eq "x86") { | |
$Host.UI.RawUI.CursorPosition = @{ X = 0; Y = $curpos + 4 } | |
Write-Host " x64 " -NoNewLine -ForegroundColor $bcolor -BackgroundColor $fcolor | |
Write-Host " x86 " -NoNewLine -ForegroundColor $fcolor -BackgroundColor $bcolor | |
$Architecture = "x64" | |
} | |
break | |
} | |
39 { | |
if ($Architecture -eq "x64") { | |
$Host.UI.RawUI.CursorPosition = @{ X = 0; Y = $curpos + 4 } | |
Write-Host " x64 " -NoNewLine -ForegroundColor $fcolor -BackgroundColor $bcolor | |
Write-Host " x86 " -NoNewLine -ForegroundColor $bcolor -BackgroundColor $fcolor | |
$Architecture = "x86" | |
} | |
break | |
} | |
13 { | |
$Channel = $verlist[$curpos].Channel | |
$Version = $verlist[$curpos].Version | |
$Download = $true | |
$navflag = $false | |
$nav2flag = $false | |
break | |
} | |
27 { | |
$Host.UI.RawUI.CursorPosition = @{ X = 0; Y = $curpos + 4 } | |
Write-Host (" {0}" -f $verlist[$curpos].Channel.PadRight(9, " ")) -NoNewLine -ForegroundColor $bcolor -BackgroundColor $fcolor | |
$nav2flag = $false | |
} | |
} | |
} while ($nav2flag) | |
} | |
27 { $navflag = $false } | |
} | |
} while ($navflag) | |
$Host.UI.RawUI.CursorPosition = @{ X = 0; Y = $verlist.Count + 5 } | |
[Console]::CursorVisible = $true | |
# exit if Esc pressed | |
if (-not $Download) { exit 0 } | |
} | |
# check if the selected version is available for download | |
Write-Host "Checking availability..." -NoNewLine | |
$Response = $null | |
$url = -join ( | |
"https://msedge.api.cdp.microsoft.com/api/v1.1/internal/contents/Browser/namespaces/Default/names/msedge-", | |
$Channel, | |
"-win-", | |
$Architecture, | |
"/versions/", | |
$Version, | |
"/files?action=GenerateDownloadInfo&foregroundPriority=true" | |
) | |
try { $Response = Invoke-RestMethod -Method Post -Uri $url } | |
catch { Get-Out -Message " fail" } | |
if ($Response) { | |
Write-Host " ok" -ForegroundColor Green | |
# start download | |
if ($Download) { | |
Write-Host "Downloading..." -NoNewLine | |
$Release = $Response | where { $_.FileId.ToLower() -eq "microsoftedge_$($Architecture)_$($Version).exe" } | |
$edgebits = @{ | |
Source = $Release.Url | |
Destination = "msedge_$($Architecture)_$($Channel)_$($Version).exe" | |
DisplayName = "$Channel $Version" | |
Description = "{0} MiB" -f [Math]::Round($Release.SizeInBytes / 1MB, 2) | |
} | |
try { Start-BitsTransfer @edgebits } | |
catch { Get-Out -Message "`nBITS failed. Try again." } | |
# extract with 7z | |
if (Test-Path -LiteralPath "msedge_$($Architecture)_$($Channel)_$($Version).exe") { | |
Write-Host " ok" -ForegroundColor Green | |
if ($Extract) { | |
Write-Host "Extracting..." | |
$sevenzip = "7z.exe" | |
if (Test-Path -LiteralPath "$PSScriptRoot\7z.exe") { $sevenzip = "$PSScriptRoot\7z.exe" } | |
try { | |
& $sevenzip x "msedge_$($Architecture)_$($Channel)_$($Version).exe" -aoa -bso0 -bsp1 -y | |
& $sevenzip x "msedge.7z" -aoa -bso0 -bsp1 -y | |
if (Test-Path -Path "Edge") { | |
Move-Item -Path "Chrome-bin\*" -Destination "Edge" -Force | |
Remove-Item -Path "Chrome-bin" -Force | |
} | |
else { Rename-Item -Path "Chrome-bin" -NewName "Edge" -Force } | |
Remove-Item -Path "msedge.7z" -Force | |
$Host.UI.RawUI.CursorPosition = @{ X = 13; Y = $Host.UI.RawUI.CursorPosition.Y - 1 } | |
Write-Host " ok" -ForegroundColor Green | |
} | |
catch { | |
$Host.UI.RawUI.CursorPosition = @{ X = 13; Y = $Host.UI.RawUI.CursorPosition.Y - 1 } | |
Get-Out -Message " fail" | |
} | |
} | |
} else { Get-Out -Message " fail" } | |
} | |
} else { Get-Out -Message " fail" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
for general check (with simplified navigation)
> .\EdgeCheck
for check specific version
for check and download specific version
if you have
7z.exe
next to the script or in$Env:path
, you can extract the installer after downloading