Skip to content

Instantly share code, notes, and snippets.

@tcartwright
Last active November 11, 2022 15:15
Show Gist options
  • Save tcartwright/63efb3d46f90f94980ffa6240d52e851 to your computer and use it in GitHub Desktop.
Save tcartwright/63efb3d46f90f94980ffa6240d52e851 to your computer and use it in GitHub Desktop.
POWERSHELL: Winget list all packages in alphabetical order
Clear-Host
# scanning winget is not perfect, but it allows you to get a list of packages avaialable from the winget store in alphabetical order.
# seems to have an issue with parsing non-english languages, possibly because of the unicode byte width
$includeUnicodeResults = $false #change this to include or exclude them from the results
$results = winget search --query `"`" |
Select-Object -Skip 3 |
ForEach-Object {
$containsUnicode = $_ -inotmatch "^Microsoft" -and ($_.ToCharArray() | Where-Object { $_ -lt 32 -or $_ -gt 255 })
try {
if ($includeUnicodeResults -or -not $containsUnicode) {
[PSCustomObject]@{
Name = $_.substring(0, 44).Trim()
Id = $_.substring(44, 36).Trim()
Version = $_.substring(80, 13).Trim()
Match = $_.substring(93, 10).Trim()
Source = $_.substring(103).Trim()
}
}
} catch {
Write-Warning "Could not parse: $($_)"
}
}
$results |
Sort-Object Name |
Format-Table
Clear-Host
# https://dev.to/antidisestablishmentarianism/search-microsoft-store-from-powershell-2bjj
Function Search-MSStore ($query, $category = "all") {
$base = "https://storeedgefd.dsx.mp.microsoft.com/v8.0/search?"; $market = "US"; $locale = "en-US"
$pageSize = 25 # ms store does not appear to allow any higher than 25....
$paramstring = [ordered]@{
market = "US"
locale = "en-US"
mediaType = "all"
query = ""
category = $category
moId = "Public"
appVersion="12006.1001.0.0"
catalogLocales="en-US"
availableOn="windows.desktop"
maturityRating="all"
cardsEnabled="true"
pzn="0"
pageSize=$pageSize
skipItems=0
}
$paramobject = New-Object -TypeName PSObject
$paramobject | Add-Member -NotePropertyMembers $paramstring
if ($query) {
$paramobject.query=$query
}
$allCards = @()
$skip = 0
$totalItems = 0
$activity = “Querying MS Store with: query=$query, category=$category”
do {
$cards = $null
# set the skip, and regen the querystring
$paramobject.skipItems = $skip
[string]$param = (-join ($paramobject.psobject.Properties.name | foreach {$_ + "=" + $paramobject.$_ + "&"})).trimend("&")
$response = Invoke-WebRequest -UseBasicParsing -Uri ($base+$param)
$content = ($response.content | ConvertFrom-Json)
# if this is the first time looping, grab the total # of items
if ($totalItems -eq 0) {
$totalItems = $content.Payload.TotalItems
}
# use math.min to handle the situations where the skip does not divide evenly into the total items, causing overflow past 100.00
Write-Progress -Activity $activity `
-Status “Queried $skip of $totalItems” `
-PercentComplete ([Math]::Min(100.00, (([decimal]$skip / [decimal]$totalItems) * 100.00)))
$cards = $content.Payload.Cards |
Select-Object Title,Price,ProductId,ProductFamilyName,Categories,AverageRating
$allCards += $cards
$skip += $pageSize
# additional cya. if the skip exceeds the total items then break out of the loop
if ($skip -gt $totalItems) {
break;
}
} while ($cards)
Write-Progress -Activity $activity -Completed
return ($allCards | Sort-Object -Property Title)
}
# use this to find package|product ids from the ms store, which can be used in the winget import json
Search-MSStore -category "developer tools" | Format-Table
Search-MSStore -query "*nuget*" | Format-Table
Search-MSStore -query "*sql*" | Format-Table
Search-MSStore -query "*ilspy*" | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment