Updating in-box apps with PowerShell

[ad_1]

It’s always the simple things that turn out to be more complicated than expected. I was deploying new machines with Windows 11 and needed to automate the process of adding PowerShell 7.4 and .NET 8 to them. That should be simple enough, I can just use Winget to install them. But there was one problem: Winget was broken, so it failed to install anything. And you can’t update Winget with Winget when Winget is broken, for obvious reasons.

I figured that there had to be a simple, automated way to update Winget, which is part of the Desktop App Installer app available on the Microsoft Store. There are WinRT APIs available to do this (as UWP apps might need to trigger the installation or updating of themselves or other apps), but how do you call those from PowerShell? That’s the hard part: pretty much everything in WinRT uses async methods, many using generic types, which makes the PowerShell logic rather complicated. Eventually I found a thread on Github that explained how to do it, with working example: https://github.com/microsoft/winget-cli/discussions/1738

So after a little cleanup and testing, I published a version of that to the PowerShell Gallery as Update-InboxApp. You can install it and run it to update a single app, like this:

Install-Script Update-InboxApp
Update-InboxApp "Microsoft.DesktopAppInstaller_8wekyb3d8bbwe"

Or you call try to update all the apps at once:

Install-Script Update-InboxApp
Get-AppxPackage | Update-InboxApp

It’s worth noting that some of the in-box apps aren’t actually updated from the Microsoft Store, so you’ll see a bunch of warnings related to that:

That’s OK, just be aware that some app updates need to be installed through other means, e.g. Windows Update.

Overall, the script ends up working pretty well to solve the original problem, and has use cases beyond that as well. But of course after doing that, I then came across another solution to the same problem, specifically around updating Winget. Andrew Taylor posted a blog about that back in December that uses the Repair-WingetPackageManager cmdlet to achieve the same result. The basic process for that:

Install-Module microsoft.winget.client -Force -AllowClobber
Import-Module microsoft.winget.client
repair-wingetpackagemanager

Behind the scenes, that Repair-WingetPackageManager cmdlet will download the latest Winget bits from Github, so it has no dependency on using Winget to update Winget. So take your pick on the approach, but at the very least be aware of the challenge when using Winget (either directly or indirectly — note that Intune uses Winget for installing store apps when you are using the “Microsoft Store app (new)” application type).



[ad_2]
Source link

Share this post via

Leave a Reply