Skip to content

Instantly share code, notes, and snippets.

@p0w3rsh3ll
Created February 16, 2020 18:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save p0w3rsh3ll/5097069509bdf235daa64cd51642530e to your computer and use it in GitHub Desktop.
Save p0w3rsh3ll/5097069509bdf235daa64cd51642530e to your computer and use it in GitHub Desktop.
#Requires -Version 6.0
Function Get-MSEdgeEnterpiseData {
<#
.SYNOPSIS
Get Json Data about Edge-Chromium from https://aka.ms/EdgeEnterprise.
.DESCRIPTION
Parse https://aka.ms/EdgeEnterprise and extract raw Json data from this web page.
.NOTES
PowerShell version 6 or later is mandatory because of the switch -AsHashtable
being used by the ConvertFrom-Json cmdlet.
#>
[CmdletBinding()]
Param()
Begin {
$HT = @{
ErrorAction = 'Stop'
UseBasicParsing = [switch]::Present
}
$originalValue = [Net.ServicePointManager]::SecurityProtocol
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$uri = 'https://www.microsoft.com/en-us/edge/business/download'
$Error.Clear()
}
Process {
if ($req = Invoke-WebRequest -Uri $uri -MaximumRedirection 0 -ErrorAction SilentlyContinue -Verbose:$false) {
if (($req | Select-Object -ExpandProperty 'RawContent') -match '\sdata-whole-json="\[(?<JsonData>.+)\]"\>') {
try {
"[$(($Matches['JsonData'] -replace '&quot;','"'))]" |
ConvertFrom-Json -AsHashtable -ErrorAction Stop
} catch {
Write-Error -Message "Failed to parse Json because $($_.Exception.Message)"
}
} else {
Write-Error -Message "Raw content doesn't match regex '\sdata-whole-json=`"\[(?<JsonData>.+)\]`"\>'"
}
} else {
Write-Error -Message "Failed to read 'https://www.microsoft.com/en-us/edge/business/download' because $($Error[0].Exception.Message)"
}
}
End {
[Net.ServicePointManager]::SecurityProtocol = $originalValue
}
}
Function Get-MSEdgeEnterpiseBuild {
<#
.SYNOPSIS
Get the channel/build info from the Json data
.DESCRIPTION
Parse https://aka.ms/EdgeEnterprise and extract the channel/build info from the raw Json data.
.PARAMETER Channel
Default channel set to 'Stable'. Accepts one or more channels as input.
.EXAMPLE
Get-MSEdgeEnterpiseBuild
.EXAMPLE
Get-MSEdgeEnterpiseBuild -Channel Stable,Dev,Beta
#>
[CmdletBinding()]
Param(
[Parameter()]
[ValidateSet('Stable','Dev','Beta')]
[string[]]$Channel = 'Stable'
)
Begin{
$Data = (Get-MSEdgeEnterpiseData)
# helper inner function
Function Get-MSEdgeEnterpiseChannel {
[CmdletBinding()]
Param()
Begin{}
Process {
try {
$Data.Product -notmatch 'EdgeUpdate|Policy'
} catch {
Write-Warning -Message "Failed to get channels because $($_.Exception.Message)"
}
}
End{}
}
}
Process {
if ($Data) {
Get-MSEdgeEnterpiseChannel|
Where-Object { $_ -in $Channel } |
ForEach-Object {
$c = $_
$Data |
Where-Object { $_.Product -eq $c }|
Select-Object -ExpandProperty 'Releases' |
ForEach-Object {
try {
[PSCustomObject]@{
Channel = $c
Architecture = $_.Architecture
ExpectedExpiryDate = [datetime]$_.ExpectedExpiryDate
Artifacts = $_.Artifacts
Platform = $_.Platform
PublishedTime = [datetime]$_.PublishedTime
ProductVersion = [version]$_.ProductVersion
ReleaseId = [int32]$_.ReleaseId
}
} catch {
Write-Warning -Message "Failed because $($_.Exception.Message)"
}
}
}
}
}
End{}
}
Function Get-MSEdgeEnterpisePlatform {
<#
.SYNOPSIS
Get the info from the Json data using a channel/build and platform supplied.
.DESCRIPTION
Parse https://aka.ms/EdgeEnterprise and extract the info from the raw Json data
using a channel/build and platform supplied.
.PARAMETER Channel
Default channel set to 'Stable'. Accepts a single channel as input.
.PARAMETER Platform
Default channel set to 'Windows x64'.
.PARAMETER Latest
Switch to retrieve only the latest version (using the ReleaseId property)
.EXAMPLE
Get-MSEdgeEnterpisePlatform
.EXAMPLE
Get-MSEdgeEnterpisePlatform -Channel Stable
#>
[CmdletBinding()]
Param(
[Parameter()]
[ValidateSet('Stable','Dev','Beta')]
[string]$Channel = 'Stable',
[Parameter()]
[ValidateSet('Windows x64','Windows x86','Windows arm','MacOS x64')]
[string]$Platform = 'Windows x64',
[Parameter()]
[switch]$Latest
)
Begin{
$Plat,$Arch = $Platform -split '\s'
$Data = (Get-MSEdgeEnterpiseBuild -Channel $Channel)
}
Process {
if ($Data) {
$v = $Data |
Where-Object { $_.Platform -eq $Plat -and $_.Architecture -eq $Arch } |
Sort-Object -Descending -Property ReleaseId
if ($Latest) {
$v | Select-Object -First 1
} else {
$v
}
}
}
End{}
}
Function Get-MSEdgeEnterpiseDownloadInfo {
<#
.SYNOPSIS
Get the download info from version(s) info supplied.
.DESCRIPTION
Get the download info of artifacts (file, hash,...) from version(s) info supplied from the pipeline.
.PARAMETER InputObject
.EXAMPLE
Get-MSEdgeEnterpisePlatform -Channel Stable | Get-MSEdgeEnterpiseDownloadInfo
.EXAMPLE
Get-MSEdgeEnterpisePlatform -Channel Stable -Latest | Get-MSEdgeEnterpiseDownloadInfo
.EXAMPLE
Get-MSEdgeEnterpisePlatform -Channel Stable -Latest -Platform 'MacOS x64' | Get-MSEdgeEnterpiseDownloadInfo
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory,ValueFromPipeline)]
$InputObject
)
Begin{}
Process {
$InputObject |
ForEach-Object {
$o = $_
(
$Artifacts = $o |
Select-Object -ExpandProperty 'Artifacts' |
Where-Object { $_.ArtifactName -in 'pkg','msi','cab','exe' }
).Keys |
ForEach-Object {
if ($_ -eq 'SizeInBytes') {
$o |
Add-Member -MemberType NoteProperty -Name 'SizeInMB' -Value ('{0:N2}'-f ([int]($Artifacts['SizeInBytes'])/1MB)) -Force
} else {
$o |
Add-Member -MemberType NoteProperty -Name $_ -Value $Artifacts["$($_)"] -Force
}
}
$o
}
}
End {}
}
Function Get-MSEdgeEnterpisePolicy {
<#
.SYNOPSIS
Get the info about policies from the Json data.
.DESCRIPTION
Parse https://aka.ms/EdgeEnterprise and extract the info about policies from the raw Json data.
.PARAMETER Latest
Switch to retrieve only the latest version (using the ReleaseId property).
.EXAMPLE
Get-MSEdgeEnterpisePolicy | Get-MSEdgeEnterpiseDownloadInfo
.EXAMPLE
Get-MSEdgeEnterpisePolicy -Latest | Get-MSEdgeEnterpiseDownloadInfo
#>
[CmdletBinding()]
Param(
[Parameter()]
[switch]$Latest
)
Begin {
$Data = (Get-MSEdgeEnterpiseData)
}
Process {
$v = $Data |
Where-Object { $_.Product -match 'Policy'} |
Select-Object -ExpandProperty 'Releases' |
ForEach-Object {
try {
[PSCustomObject]@{
Channel = 'Policy'
Architecture = $_.Architecture
ExpectedExpiryDate = [datetime]$_.ExpectedExpiryDate
Artifacts = $_.Artifacts
Platform = $_.Platform
PublishedTime = [datetime]$_.PublishedTime
ProductVersion = [version]$_.ProductVersion
ReleaseId = [int32]$_.ReleaseId
}
} catch {
Write-Warning -Message "Failed because $($_.Exception.Message)"
}
}
if ($Latest) {
$v | Select-Object -First 1
} else {
$v
}
}
End {}
}
Function Get-MSEdgeEnterpiseEdgeUpdateInfo {
<#
.SYNOPSIS
Get the info about Edge Update from the Json data.
.DESCRIPTION
Parse https://aka.ms/EdgeEnterprise and extract the info about Edge Update(s) from the raw Json data.
.PARAMETER Latest
Switch to retrieve only the latest version (using the ReleaseId property).
.EXAMPLE
Get-MSEdgeEnterpiseEdgeUpdateInfo | Get-MSEdgeEnterpiseDownloadInfo
#>
[CmdletBinding()]
Param(
[Parameter()]
[switch]$Latest
)
Begin {
$Data = (Get-MSEdgeEnterpiseData)
}
Process {
$Data |
Where-Object { $_.Product -match 'EdgeUpdate'} |
Select-Object -ExpandProperty 'Releases' |
ForEach-Object {
try {
[PSCustomObject]@{
Channel = 'EdgeUpdate'
Architecture = $_.Architecture
ExpectedExpiryDate = [datetime]$_.ExpectedExpiryDate
Artifacts = $_.Artifacts
Platform = $_.Platform
PublishedTime = [datetime]$_.PublishedTime
ProductVersion = [version]$_.ProductVersion
ReleaseId = [int32]$_.ReleaseId
}
} catch {
Write-Warning -Message "Failed because $($_.Exception.Message)"
}
}
}
End {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment