Created
September 22, 2025 17:01
-
-
Save DailenG/75d29659d73249a02a790527004dd1c3 to your computer and use it in GitHub Desktop.
Get-NetExtender
This file contains hidden or 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
function Get-NetExtender { | |
<# | |
.SYNOPSIS | |
Gets SonicWall NetExtender metadata (version, URL, MD5) from the official API. | |
.DESCRIPTION | |
Calls SonicWall's Free Downloads API for NetExtender, filters by platform, | |
and returns a tidy object. By default returns the latest; with -Version, | |
returns the specified version (exact match by default, or prefix match with -AllowPrefixMatch). | |
.PARAMETER Platform | |
Target platform. Valid: Windows-x64 (default), Windows-x86, macOS, Linux. | |
.PARAMETER Version | |
Specific version to return (e.g., "10.3.2"). Exact match unless -AllowPrefixMatch is used. | |
.PARAMETER AllowPrefixMatch | |
If set with -Version, allows prefix matches (e.g., "10.3" will select the highest "10.3.*"). | |
.OUTPUTS | |
PSCustomObject: Product, Platform, Version, FileName, Url, Md5, Source. | |
.EXAMPLE | |
Get-NetExtender | |
# Latest Windows x64 metadata. | |
.EXAMPLE | |
Get-NetExtender -Version 10.3.2 | |
# Exact version for Windows x64. | |
.EXAMPLE | |
Get-NetExtender -Version 10.3 -AllowPrefixMatch | |
# Highest 10.3.* for Windows x64. | |
.EXAMPLE | |
(Get-NetExtender -Platform Windows-x86).Url | |
# Just the download URL for latest Windows x86. | |
#> | |
[CmdletBinding()] | |
param( | |
[ValidateSet('Windows-x64','Windows-x86','macOS','Linux')] | |
[string]$Platform = 'Windows-x64', | |
[string]$Version, | |
[switch]$AllowPrefixMatch | |
) | |
# Ensure TLS 1.2+ (older hosts) | |
if (-not ([System.Net.ServicePointManager]::SecurityProtocol -band [System.Net.SecurityProtocolType]::Tls12)) { | |
[System.Net.ServicePointManager]::SecurityProtocol = | |
[System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12 | |
} | |
$uri = 'https://api.mysonicwall.com/api/downloads/get-freedownloads' | |
$body = @{ | |
category = 'LATEST' | |
productType = '17491' # NetExtender | |
swLangCode = 'EN' | |
fileType = @('Firmware') | |
releaseTypeList = @(@{ releaseType = 'ALL' }) | |
keyWord = '' | |
previousVersions = $false | |
isFileTypeChange = $false | |
username = 'ANONYMOUS' | |
} | ConvertTo-Json | |
$headers = @{ | |
'Accept' = 'application/json' | |
'User-Agent' = 'PowerShell Get-NetExtender' | |
} | |
try { | |
$resp = Invoke-RestMethod -Method Post -Uri $uri -ContentType 'application/json' -Headers $headers -Body $body -TimeoutSec 60 | |
# Gather all "applicableDownloads" and locate the NetExtender block | |
$blocks = @() | |
if ($resp.content -and $resp.content.UserDownloads) { | |
foreach ($ud in $resp.content.UserDownloads) { | |
if ($ud.applicableDownloads) { $blocks += $ud.applicableDownloads } | |
} | |
} | |
$nx = $blocks | Where-Object { $_.Name -eq 'NetExtender' } | Select-Object -First 1 | |
if (-not $nx -or -not $nx.softwareList) { | |
throw "NetExtender not found in API response." | |
} | |
# Map our platform to SonicWall label | |
$label = switch ($Platform) { | |
'Windows-x64' { 'Windows 64 bit' } | |
'Windows-x86' { 'Windows 32 bit' } | |
'macOS' { 'macOS' } | |
'Linux' { 'Linux' } | |
} | |
$candidates = $nx.softwareList | Where-Object { $_.name -like "*$label*" } | |
if (-not $candidates) { | |
throw "No packages found for platform '$Platform'." | |
} | |
$pkg = $null | |
if ($Version) { | |
if ($AllowPrefixMatch) { | |
# Pick the highest version that starts with the requested prefix | |
$pkg = $candidates | | |
Where-Object { $_.Version -like "$Version*" } | | |
Sort-Object -Property @{Expression='Version';Descending=$true} | | |
Select-Object -First 1 | |
} else { | |
$pkg = $candidates | Where-Object { $_.Version -eq $Version } | Select-Object -First 1 | |
} | |
if (-not $pkg) { | |
$available = ($candidates.Version | Sort-Object -Descending) -join ', ' | |
throw "Version '$Version' not found for $Platform. Available: $available" | |
} | |
} else { | |
# Latest | |
$pkg = $candidates | Sort-Object -Property @{Expression='Version';Descending=$true} | Select-Object -First 1 | |
} | |
# Construct filename/URL for Windows; use API fields for others if present | |
$fileName = $null | |
$url = $null | |
if ($Platform -like 'Windows-*') { | |
$fileName = if ($Platform -eq 'Windows-x64') { "NetExtender-x64-$($pkg.Version).msi" } else { "NetExtender-x86-$($pkg.Version).msi" } | |
$url = "https://software.sonicwall.com/NetExtender/$fileName" | |
} else { | |
$fileName = $pkg.fileName | |
$url = $pkg.downloadLink | |
} | |
[pscustomobject]@{ | |
Product = 'NetExtender' | |
Platform = $Platform | |
Version = $pkg.Version | |
FileName = $fileName | |
Url = $url | |
Md5 = $pkg.md5HashValue | |
Source = 'API' | |
} | |
} | |
catch { | |
throw "Get-NetExtender failed: $($_.Exception.Message)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment