Deploying software packages with Winget

In the first part of this two-part article, IT veteran Jeffrey Hicks introduced us to software package management using Windows Package Manager (Winget), Microsoft’s new command-line-based package manager for Windows. He explained what package management is all about and walked us through installing and configuring Winget. In this second and final article, Jeffrey shows us how to use Winget to find packages, install and uninstall them, and update them.

Finding packages

The easiest way to find packages is to search by name.

Winget

Winget lets you search by a package name, its ID, or a tag. Wildcard searches won’t work. Sometimes you have to be creative because you’ll get different responses depending on how you search.

Winget

By the way, if you run Winget search, you’ll get a list of all packages, which is more than 2,600 as I write this.

Getting package details

Once you’ve identified a package, you can get details about it with the Show command.

Winget

I find it easiest to let Winget figure out how to find the package. Although you can be more specific by using –id or –name.

Installing packages

Installing a package is generally pretty easy.

The installation is generally automatic, although you might see install screens. Note that you have no real control over the installation. The package will be installed using the vendor’s or creator’s default settings.

It should also go without saying, but I will anyway, that you should only install packages from trusted sources. I have no problem installing a package from Microsoft or Google, but I will be leery about a package from someone I’ve never heard of. This is where the show command is useful. If there is a home page or a GitHub repository I can check out, so much the better.

If you need to take a more granular approach, the installer has a few options.

I’m going to install VSCode completely silently with the “user” scope:

Winget install vscode -h --scope user

You can only install a single package at a time. But you could always make a text file with package names or IDs:

Mozilla.firefox
Github.cli
Dropbox.dropbox
wireshark

Then use PowerShell and the Foreach-Object cmdlet:

Get-Content c:\work\apps.txt | foreach-object { Winget install $_ --silent}

You can also use the export option in Winget to create a JSON file of installed applications. You’ll probably see errors about other packages which you can ignore. The JSON file will only contain packages you installed with Winget. Later, or on another machine, you can import the JSON file and have Winget install the packages:

Winget import c:\work\packages.json

Updating packages

There is not an automatic mechanism to inform you if a given package has an update available. If you run Winget upgrade you’ll get a list of all packages that have an available update:

You can update a single package:

Winget upgrade --id Microsoft.Edge

Or if there are multiple packages, you can have Winget upgrade everything:

Winget upgrade --all --silent

One word of caution: Upgrading a package may cause a reboot, and there’s no way to know in advance if that will be required. Nor is there a way that I have found to defer the reboot. I was updating packages as I wrote this, and my computer rebooted in the middle of my work. A reboot might also interrupt Winget from upgrading the remaining packages. You might have to rerun the upgrade command.

Uninstalling packages

If you decide to remove a package, identify it by name or ID and run a command like this:

Managing Winget with PowerShell

If you are like me, PowerShell is your default console window. I run all of my Winget commands in it. For the most part, I have no problems. But this is a command-line tool that generates text output. If you search around, you’ll likely find a number of PowerShell modules that try to wrap Winget in a PowerShell function. I have such a module as well that you can install from the PowerShell Gallery:

Install-Module WingetTools -force

The module’s GitHub repository can be found at this GitHub page.

You can use some module commands without having Winget installed. In fact, you can install Winget with this module in a Windows PowerShell session:

Install-Winget

The install command will also download any missing pre-requisites. Run Get-WGReleaseNote to view information about the latest release.

Because I wanted to see more information about a package, I wrote Get-WGPackage:

Winget

This default view limits the properties. But there is more:

Yes, this is the same information from Winget “Show” command, but this output is an object. I wrote the command so you could also pipe a Winget search to it:

Winget search slack | Get-WGPackage

I’ll let you try that for yourself.

PowerShell limitations

Because of the way Winget is coded, it has some odd behavior that might throw you. In short, Winget must be run by a user in an interactive console. As I mentioned earlier, you cannot run Winget in a remote session using Invoke-Command or SSH. This also means you can’t run Winget in a PowerShell background job.

I was able to use psexec from Sysinternals to run Winget remotely, and in my limited testing, using a PowerShell scheduled job or the Windows Task Manager should work.

There was talk about an official set of PowerShell cmdlets for Winget, but given everything I see on the Winget team’s plate, I wouldn’t expect to see anything in the foreseeable future.

Your action plan

It may feel that I’m pessimistic about Winget, and that isn’t entirely true. Yes, there are limitations that I find annoying. I’m hoping some of them will be addressed in the future. But I am happy to use Winget on almost a daily basis to keep packages up to date and synchronized across machines. If you are comfortable with a command prompt, I encourage you to give Winget a try. Even though the bits I’m using today are technically prerelease, I rarely encounter problems.

Download and install from GitHub. Or if Winget is available in the Microsoft Store by the time you read this, install it from there, so you get automatic updates. I know that’s what I’ll be doing when the time comes.

Then use Winget to install or reinstall your essential desktop applications. This makes it easier to keep them up to date. I manually run the Winget upgrade process. If I could ensure that my computer wouldn’t reboot, I’d try to use a scheduled task. But we’re not there yet.

Finally, I’d encourage you to use Winget’s export feature. You can use the JSON file to reinstall if you have to rebuild your desktop or to synchronize a second computer like a laptop. It is simple enough to create batch files or PowerShell scripts to automate these tasks.

I’m curious to see where Winget goes from here because somehow, it has become an integral part of how I work!

Featured image: Shutterstock

About The Author

1 thought on “Deploying software packages with Winget”

  1. Hi, Thanks for nice article. How secure is Winget repo ? How can I know that a package is good ? As I understand Microsoft does not maintain the packages ? How can I know if a packaged is maintained by the vendor ? Thanks for reply

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top