DEV Community

uyriq
uyriq

Posted on

Streamline Your Winget Package Updates with PowerShell

For me, updating packages using Winget is almost a daily operation. At least once a day, I type winget update in the terminal to see what’s new for the already installed software. I don’t always update, but sometimes (about every other day), I manually copy and paste package IDs one by one. That’s how wup was born—a PowerShell script that automates working with Winget and made my life easier (it took just two evenings to debug it).

About the Problem, More Formally

Each time I need to update a bunch of packages using Winget, I create a line in the PowerShell session similar to this, which involves a lot of copying and pasting:

winget update --id package.id1; winget update --id package.id2; ... ; winget update --id package.idN
Enter fullscreen mode Exit fullscreen mode

Description of the Image

It’s not only tedious but also gets complicated because sometimes --id doesn’t work as expected, as mentioned here. Due to this, I need to use --name instead of --id for updating some packages like pnpm. Such cases are not rare, and sometimes it's the opposite—you can't update by name but can by --id.

The Solution

To solve this problem, I wrote a PowerShell script that lists all possible updates for installed packages when called without arguments, essentially just showing the result of winget update. Then, you can call the script with an argument: it accepts a list of package IDs and updates the listed packages. Note: I still copy and paste the IDs of the desired packages. The copy-paste hasn’t disappeared 😅 ("HelpWanted, need a fzv feature!")

Description of the Image

Here’s a brief overview of the script:

  1. List All Updates: If the script is called without any arguments, it lists all possible updates for the installed packages.
  2. Update Specific Packages: If package IDs are provided as arguments, it updates only those specific packages.

How to Use the Script

  1. Download the Script: Get the script and its README from this gist.
  2. Place the Script Anywhere: Place the script in any directory of your choice.
  3. Set Alias in $PROFILE: Add an alias to your $PROFILE for easy access.
Set-Alias -Name wup -Value "Path\To\Script.ps1"
Enter fullscreen mode Exit fullscreen mode

Now, you can simply run wup in your PowerShell session to get the list of updates or provide specific package IDs for updating.


Notes

The gist with the script contains a Readme.md with additional PowerShell thoughts.

If you have any questions or improvements, feel free to contribute!

All code is licensed under the MIT License. Happy updating!


By the way, did you hear about the scrambled [python, not pwsh] developer who couldn’t find his packages? He said, "I guess I’m just egg-sasperated!" 🥚

Top comments (1)

Collapse
 
uyriq profile image
uyriq

Sorry if the joke is too pytonish, not powershelish