4

Is there a way to list only packages installed specifically with the winget command?

winget list

seems to show all packages installed on the machine.

I am changing my computer and I want to get a list of all packages I installed with winget to be installed on the new machine. Is this possible?

pooya13
  • 2,060
  • 2
  • 23
  • 29

5 Answers5

6

To narrow the display output to those packages available via winget, use the following:

(winget list) -match ' winget$'

Unfortunately, this isn't the same as those which you actually installed via winget,Tip of the hat to Demitrius Nelon:

  • As of version v1.4.10173 of winget, there is no way to get this information.

  • GitHub issue #1155 proposes future enhancements to winget list

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    @mklement0 It's a little different from what you stated. It's showing packages that appear to have a matching entry (package manifest) in a configured source. The default sources are "winget" for the community repository and "msstore" for the Microsoft Store source. Additional REST sources could also be added. – Demitrius Nelon Feb 15 '23 at 22:21
  • 1
    I appreciate the correction, @DemitriusNelon - please see my update. – mklement0 Feb 15 '23 at 22:55
  • 1
    P.S., @DemitriusNelon: _most_ Microsoft-originated packages show _no_ value in the "source" column for me (rather than "msstore"), as of winget version 1.4.10173); yet _some_ - e.g. `Microsoft.OneDriive` - do. – mklement0 Feb 15 '23 at 23:17
  • 1
    That's correct. If the package was installed via WinGet from the Microsoft Store, the ID would look like a string of characters (like: 9NBLGGH4NNS1 - The App Installer which contains WinGet) and it would show a match with the "msstore" source. We're still working to improve matching. – Demitrius Nelon Mar 01 '23 at 01:36
4

No, there is no way to have WinGet display packages it has installed.

The output of list is coming from the same source as "Windows Apps & Features". The filtering by source is just a request for displaying packages available in more than one source to the one specified.

An enhancement has been asked for to filter the results only to packages available in a given source.

Demitrius Nelon
  • 1,210
  • 1
  • 10
  • 29
  • 1
    Thank you. So even with the proposed filter it wouldn't be possible to show packages installed by WinGet right? – pooya13 Feb 03 '23 at 01:58
  • 1
    That's correct. WinGet tracks what it installed, but the user could make many changes to the machine without using WinGet, so it's not really a "reliable" mechanism for knowing how the machine got to its current state. – Demitrius Nelon Feb 15 '23 at 22:08
  • This is a correct, and totally regrettable, answer. – BobHy Jun 29 '23 at 17:27
2

You probably got your answer for this, but for those showing up via Google, here's a few current (as of 2023-04-19) helpful commands that work with Windows 10 (and I assume Windows 11).

As a side note, I never used WinGet to install anything on this PC, so it's nice that WinGet now shows apps that are compatible with WinGet even if they weren't installed with it.


WinGet Version Used: 1.5.441-preview

List Apps with Source = Winget: winget list --source "winget"

This gives you a filtered list in the terminal that have their source as "Winget". From what I can tell, any app that it can match an ID to in the repository is listed, regardless of how it was originally installed (nice!).

Side tip, you can export this list by piping the output to a file, example:

winget list --source "winget" > "C:\temp\__MyOutput.txt"

Export JSON Manifest of WinGet Programs winget export -o "C:\temp\__ListApps.txt"

This exports a JSON manifest that can be directly imported using the import command (example below). Change the "C:\temp__ListApps.txt" to whatever you wish. There are a few additional command options you can use: https://learn.microsoft.com/en-us/windows/package-manager/winget/export


Import JSON Manifest of WinGet Programs winget import -i "C:\temp\__ListApps.txt"

Use this to import that manifest for automated installation. Change the "C:\temp__ListApps.txt" to whatever you wish. Additional info: https://learn.microsoft.com/en-us/windows/package-manager/winget/import


There's also a lot of query functionality so you can filter the lists as you see fit, check the WinGet documentation here: https://learn.microsoft.com/en-us/windows/package-manager/winget/list

Kyle K.
  • 306
  • 4
  • 3
  • Unfortunately, this is not what my question is about. Imagine you are changing your workstation and want to install only what you have installed yourself. However, after you export ALL packages with winget source, you will end up with entries that were installed by default in the previous version of Windows, but are now considered to be harmful, incompatible or deprecated in the new version of Windows. – pooya13 Jun 17 '23 at 17:32
0

As noted above, the answer to your question remains "no", even to this very day.

However, this command shows the list of applications that winget can update, whether originally installed by winget or other means.

winget update

Maybe it's a useful partial answer?

BobHy
  • 1,575
  • 10
  • 23
0

This is not perfect, but it's as close as I was able to get. I had the same objective as you. Trying to create a script that I could run on a new windows machine to install all my packages through winget.

In PowerShell run:

$winget_packages = ((winget list) -match ' winget$' | Select-String -Pattern "(?<= {2,})(?!\d+\.\d+)\S+(?= {2,})") | foreach {$_.Matches.Value}

$winget_script = (echo '@echo off

winget install ' ($winget_packages -replace "$", " ")
)

$winget_script | Set-Content install_winget_packages.bat -NoNewLine

Essentially what does this does is grab the list of installed programs with a "winget" source^1. It then takes the text preceded and followed by two or more spaces that is not a version number (X.X+) and gets the matched value into winget_packages^2.

Finally it puts winget install in front, adds a space at the end, and writes it all to a .bat file with the newlines collapsed.

1: As @DemitriusNelon points out this is not those you actually installed with winget, but I don't think that's much of a problem since I generally would rather they were if the source is available. In situations where I don't want this. I manually take those couple out.

2: This fails in cases where the package name is so long that there aren't two space but not long enough that it doesn't produce the error characters ….