Winget shipped without PowerShell support

Why would you need that?

I previously wrote about how impressed I was with winget, the official Windows package manager. This morning went to upgrade some packages on my system and received the following error:

winget upgrade --all -h

Package agreements were not agreed to. Operation cancelled.

Not the most descriptive error, but some cursory searching pulled up the --accept-package-agreements flag. But! it can’t be run with the --all flag, so you’d have grab each package that failed to upgrade and accept the agreement.

winget install --id Microsoft.PowerShell --accept-package-agreements

I had 3 packages failing the agreement check, so I thought I could be smart this morning and write a PowerShell script to automate this for me. That’s the great thing about package managers and the command line, right?

winget upgrade
Name Id Version Available Source
OBS Studio OBSProject.OBSStudio 28.1.2 29.0.2 winget
PowerShell Microsoft.PowerShell winget
2 upgrades available.
2 package(s) have version numbers that cannot be determined. Use --include-unknown to see all results.

winget upgrade and winget list both output a table of packages. Armed with newfound knowledge of PowerShell’s Select-Object to grab a column, and GitHub CoPilot, I wrote the following script:

# list packages with an update
$packages = winget upgrade | Select-Object Id

# for each package with an update, install and accept agreements
$packages | ForEach-Object {
$package = $_.split(" ")
$package = $package[0]
$package = $package.Trim()
winget install $package --accept-package-agreements

…which immediately fails on line 2, because winget’s output is not a PowerShell object, breaking convention with most other things in Windows. The table that winget list and winget upgrade produced is a string!

There’s an open issue on GitHub for the lack of PowerShell support, and it looks like they’re slowly working on adding a PowerShell Module. That’s great, but I’m still surprised winget shipped without PowerShell support.