How to Upgrade Packages with WinGet Module in PowerShell?

0
2
Asked By SunnyDay42 On

Hey everyone! I'm a fan of using the PowerShell version of WinGet because it provides actual objects to work with, rather than the cluttered output from the CLI. However, I've noticed that, unlike the CLI, the PowerShell module reinstalls a package every single time, even if there's no upgrade available. This seems like a waste of time and resources. I'm looking for a way to make the PowerShell module mimic the CLI behavior by upgrading the package when it's found and skipping it if no upgrades are available. Any suggestions?

4 Answers

Answered By SunnyDay42 On
Answered By DevExpert24 On

I get what you're trying to do, but it seems like you're going in circles. The CLI is thoroughly tested, while you're trying to recreate something that’s already complete. Just use the command `winget upgrade company.product` and you’ll be good to go!

Answered By TechNinja99 On

You can use a command like this: `Get-WinGetPackage | Where-Object IsUpdateAvailable -eq $true | Upgrade-WinGetPackage`. It'll check for updates and upgrade only if there's something available.

Answered By CodeGuru77 On

What do you have set up so far?

SunnyDay42 -

I've created a wrapper function that checks if a package is installed with `Get-WinGetPackage`. Depending on whether an update is available, I either call `Update-WinGetPackage`, and if not, I use `Install-WinGetPackage`. It's not perfect, but it's working for me. Let me know if you'd like to see the code!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.