Skip to content

Instantly share code, notes, and snippets.

@maravedi
Created January 29, 2025 20:00
Show Gist options
  • Save maravedi/4a8068bdd824c1d299c023ff4cedb19c to your computer and use it in GitHub Desktop.
Save maravedi/4a8068bdd824c1d299c023ff4cedb19c to your computer and use it in GitHub Desktop.
Helper functions for finding the direct download URL for Microsoft Remote Desktop Client installers
function Get-RemoteDesktopVersions {
[CmdletBinding()]
param()
try {
# Use GitHub's API to get the directory listing
$apiUrl = "https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/m/Microsoft/RemoteDesktopClient"
# GitHub API requires a user agent
$headers = @{
'User-Agent' = 'PowerShell Script'
}
$response = Invoke-RestMethod -Uri $apiUrl -Headers $headers -ErrorAction Stop
# Extract and sort the versions
$versions = $response |
Where-Object { $_.type -eq "dir" } |
Select-Object -ExpandProperty name |
ForEach-Object {
# Create version object for proper sorting
[PSCustomObject]@{
VersionString = $_
Version = [version]($_ -replace '\.0$') # Remove trailing .0 for version comparison
}
} |
Sort-Object -Property Version -Descending |
Select-Object -ExpandProperty VersionString
return $versions
}
catch {
if ($_.Exception.Response.StatusCode -eq 404) {
Write-Warning "Remote Desktop Client directory not found in winget-pkgs repository"
}
else {
Write-Error "Error fetching versions: $_"
}
}
}
function Get-RemoteDesktopInstallerUrl {
param (
[Parameter(Mandatory)]
[string]$version,
[string]$architecture = "x64"
)
Write-Host "Searching for Remote Desktop version $version ($architecture)..." -ForegroundColor Cyan
try {
# Construct the raw GitHub URL for the manifest
$manifestUrl = "https://raw.githubusercontent.com/microsoft/winget-pkgs/master/manifests/m/Microsoft/RemoteDesktopClient/$version/Microsoft.RemoteDesktopClient.installer.yaml"
# Fetch the manifest content
$yamlContent = Invoke-RestMethod -Uri $manifestUrl -ErrorAction Stop
# Using regex to extract the specific architecture URL
$pattern = "(?smi)- Architecture: $architecture.*?InstallerUrl: (https://[^\r\n]+)"
if ($yamlContent -match $pattern) {
$installerUrl = $matches[1]
# Create custom object with relevant information
[PSCustomObject]@{
Version = $version
Architecture = $architecture
InstallerUrl = $installerUrl
ManifestUrl = $manifestUrl
}
}
else {
Write-Warning "No $architecture installer found in manifest."
}
}
catch {
if ($_.Exception.Response.StatusCode -eq 404) {
Write-Warning "No manifest found for version $version"
}
else {
Write-Error "Error fetching manifest: $_"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment