microsoft / winget-cli

WinGet is the Windows Package Manager. This project includes a CLI (Command Line Interface), PowerShell modules, and a COM (Component Object Model) API (Application Programming Interface).
https://learn.microsoft.com/windows/package-manager/
MIT License
23.37k stars 1.45k forks source link

Add a `winget list --json` #4965

Closed georgettica closed 1 week ago

georgettica commented 2 weeks ago

I might be the only one here, but I want to extract all of the data I have in winget to json so I can quickly retrieve a substet of apps from the list

Is that already available?

mdanish-kh commented 2 weeks ago

Have you tried using the WinGet PowerShell module?

You can use Get-WinGetPackage cmdlet (equivalent to winget list). Use Get-Help Get-WinGetPackage -Full to see all available capabilities of the cmdlet (there are examples available at the end of help text)

mdanish-kh commented 2 weeks ago

There is also a winget export command that can export all installed files to a json file

winget export -o file.json

Conversely, there's a winget import command too that lets you install all exported applications from the exported json files with one command

stephengillie commented 1 week ago

The output is modest:

PS C:\ManVal> Get-WinGetPackage | ConvertTo-Json
[
  {
    "InstalledVersion": "2.47.0.2",
    "Name": "Git",
    "Id": "Git.Git",
    "IsUpdateAvailable": false,
    "Source": "winget",
    "AvailableVersions": [
      "2.47.0.2",
      "2.47.0",
      "2.46.2",
      "2.46.1",
      "2.46.0",
      "2.45.2",
      "2.45.1",
      "2.45.0",
      "2.44.0",
      "2.43.0",
      "2.42.0.2",
      "2.42.0",
      "2.41.0.3",
      "2.41.0.2",
      "2.41.0",
      "2.40.1",
      "2.40.0",
      "2.39.2",
      "2.39.1",
      "2.39.0.2",
      "2.39.0",
      "2.38.1",
      "2.38.0",
      "2.37.3",
      "2.37.2.2",
      "2.37.1",
      "2.37.0",
      "2.36.1",
      "2.36.0",
      "2.35.3",
      "2.35.2",
      "2.35.1.2",
      "2.35.1",
      "2.35.0",
      "2.34.1",
      "2.34.0",
      "2.33.1",
      "2.33.0.2",
      "2.33.0",
      "2.32.0.2",
      "2.32.0",
      "2.31.1",
      "2.31.0",
      "2.30.2",
      "2.30.1",
      "2.30.0.2",
      "2.29.2.3",
      "2.29.2.2",
      "2.29.0",
      "2.28.0",
      "2.27.0",
      "2.26.2",
      "2.25.1",
      "2.24.1.2"
    ]
  },
. . .
denelon commented 1 week ago

We've released the Microsoft.WinGet.Client PowerShell module to address customers wanting JSON output.