pooya13
pooya13

Reputation: 2691

List all packages installed with winget

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?

Upvotes: 15

Views: 27244

Answers (6)

stemarcoh
stemarcoh

Reputation: 151

Winget is nothing more than a simple a way to get and install packages (any software with an installer) and to upgrade packages that are on your machine, regardless of how they were first installed. So, it can easily upgrade packages installed with winget, with Chocolatey, with MS Store, or directly using an MSI.

But winget does not keep any type of record on your machine when it installs or upgrades a package. Even trying to compare and combine output from choco list and the Registry Uninstall folder, there's no connection to winget.

My solution: Create a winget wrapper

Create a thin PowerShell wrapper of the winget command ((command winget).source) that maintains its own local catalog of packages it installed or uninstalled over time.

You can even point to the wrapper.ps1 by defining your own winget alias to override the winget command.

Simple and effective. You just need to remember to use that on new machines before starting your setup.

Alternative: Get-Installed

Unless you only ever install packages with winget, then even such a catalog may not be a complete picture of what's on your system. If you want to duplicate another machine (without creating a cloned image) then you need to include choco, msi, MS Store, and possibly other installers.

There is a Get-Installed PowerShell script that scans the Registry Uninstall folders (both 32 and 64 bit) and optionally apps installed by MS Store and generates a report.

I've used this many times in the past to accomplish what the OP wanted to do!

Upvotes: 1

Anthony Flores
Anthony Flores

Reputation: 21

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 ….

Upvotes: 2

BobHy
BobHy

Reputation: 1734

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?

Upvotes: 2

Kyle K.
Kyle K.

Reputation: 366

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

Upvotes: 3

mklement0
mklement0

Reputation: 438143

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

Upvotes: 16

Demitrius Nelon
Demitrius Nelon

Reputation: 1248

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.

Upvotes: 4

Related Questions