Last active
February 19, 2024 10:27
-
-
Save JimMoyle/5826fb2b6bb4652c725b46abc6b46a10 to your computer and use it in GitHub Desktop.
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
function Get-WpmRestApp { | |
[CmdletBinding()] | |
Param ( | |
[Parameter( | |
Position = 0, | |
ValuefromPipelineByPropertyName = $true, | |
ValuefromPipeline = $true, | |
Mandatory = $true | |
)] | |
[Alias('Id')] | |
[System.String]$PackageIdentifier, | |
[Parameter( | |
ValuefromPipelineByPropertyName = $true | |
)] | |
[System.Uri]$Uri = 'https://pkgmgr-wgrest-pme.azurefd.net/api/packageManifests/', | |
[Parameter( | |
ValuefromPipelineByPropertyName = $true | |
)] | |
[Int]$ApiTimeoutSeconds = 90 | |
) | |
begin { | |
Set-StrictMode -Version Latest | |
} # begin | |
process { | |
Write-Verbose "Querying $PackageIdentifier from $Uri" | |
$queryUri = $Uri.ToString().TrimEnd('/') + '/' + $PackageIdentifier | |
$noResponse = $true | |
$timeSpan = (Get-Date).AddSeconds($ApiTimeoutSeconds) | |
while ($noResponse) { | |
if ((Get-Date) -gt $timeSpan) { | |
Write-Error "Timeout waiting for $PackageIdentifier response from $queryUri" | |
return | |
} | |
try { | |
$package = Invoke-RestMethod -Uri $queryUri -ErrorAction Stop | |
$noResponse = $false | |
} | |
catch { | |
Start-Sleep -Milliseconds 500 | |
} | |
} | |
if ($null -eq $package) { | |
Write-Error "Could not find package with Id $PackIdentifier" | |
return | |
} | |
try { | |
$packageNewest = $package.Data.Versions | Select-Object @{Name = 'PackageVersion'; Expression = { [Version]$_.PackageVersion } }, Installers, DefaultLocale | |
if (($packageNewest.PackageVersion | Measure-Object).Count -eq 0) { | |
$packageNewest = $package.Data.Versions | Select-Object @{Name = 'PackageVersion'; Expression = { | |
$_.PackageVersion -match "(\D{0})(\d+)((\.{1}\d+)*)(\.{0})" | Out-Null | |
if ($($Matches[0]) -notlike "*.*") { | |
[Version]($Matches[0] + ".0") | |
} | |
else { | |
[Version]$Matches[0] | |
} | |
} | |
} , Installers, DefaultLocale | |
} | |
} | |
catch { | |
Write-Output $_ | |
} | |
$packageDetail = $packageNewest | Sort-Object -Property PackageVersion -Descending | Select-Object -First 1 | |
$timeSpan = (Get-Date).AddSeconds(30) | |
$appInfo = $null | |
while (($appInfo | Measure-Object).Count -eq 0 ) { | |
if ((Get-Date) -gt $timeSpan) { | |
Write-Error "Timeout waiting for version query match for $PackIdentifier" | |
return | |
} | |
$appInfo = $package.Data.versions | Where-Object { -join $_.Installers.InstallerSha256 -eq -join $packageDetail.Installers.InstallerSha256 } | |
} | |
foreach ($installer in $packageDetail.Installers) { | |
$output = [PSCustomObject]@{ | |
PackageName = $package.Data.PackageIdentifier | |
PackageVersion = $packageDetail.PackageVersion | |
Publisher = $appInfo.DefaultLocale.Publisher | |
ShortDescription = $appInfo.DefaultLocale.ShortDescription | |
InstallerIdentifier = $installer.InstallerIdentifier | |
InstallerSha256 = $installer.InstallerSha256 | |
InstallerUrl = $installer.InstallerUrl | |
Architecture = $installer.Architecture | |
InstallerType = $installer.InstallerType | |
Scope = if ($installer.PSobject.Properties.Name -contains 'Scope') { $installer.Scope } else { $null } | |
InstallerSwitches = if ($installer.PSobject.Properties.Name -contains 'InstallerSwitches') { $installer.InstallerSwitches } else { $null } | |
Commands = if ($installer.PSobject.Properties.Name -contains 'Commands') { $installer.Commands } else { $null } | |
InstallerAbortsTerminal = $installer.InstallerAbortsTerminal | |
ReleaseDate = $installer.ReleaseDate | |
InstallLocationRequired = $installer.InstallLocationRequired | |
RequireExplicitUpgrade = $installer.RequireExplicitUpgrade | |
DisplayInstallWarnings = $installer.DisplayInstallWarnings | |
DownloadCommandProhibited = $installer.DownloadCommandProhibited | |
} | |
Write-Output $output | |
} | |
} # process | |
end {} # end | |
} #function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@pl4nty this API isn't publicly supported no.