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
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!
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.
What do you have set up so far?
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!