winget-cli icon indicating copy to clipboard operation
winget-cli copied to clipboard

Winget Powershell Modules do not run on Windows PowerShell (5.1)

Open gknutson1 opened this issue 2 years ago • 6 comments

Brief description of your issue

On new Windows 11 installs, after updating Winget and installing dependencies, Several of the PowerShell commands do not work and will throw Exception has been thrown by the target of an invocation. Currently, all the WinGetPackage commands (Get-WingetPackage, Uninstall-WingetPackage, etc.) throw the error.

Adding -Verbose and -Debug does not give any additional output. Get-WingetVersion works as expected (returns v1.4.10173). The other commands (the various WingetSetting and WingetSource commands) do not throw this error either.

The Winget command itself works fine - I can search, list, and install like normal.

The above behavior occurs when using Powershell v7.3.1. Using the Windows built in Powershell (v5.1.22621.963 for me), I cannot even import the module. running import-module .\Microsoft.WinGet.Client.psd1 -Verbose there gives the following output:

VERBOSE: Loading module from path
'C:\Users\main\Desktop\Microsoft.WinGet.Client-PSModule\Microsoft.WinGet.Client.psd1'.
VERBOSE: Loading 'FormatsToProcess' from path 'C:\Users\main\Desktop\Microsoft.WinGet.Client-PSModule\Format.ps1xml'.
VERBOSE: Loading module from path
'C:\Users\main\Desktop\Microsoft.WinGet.Client-PSModule\x64\Desktop\Microsoft.WinGet.Client.dll'.
import-module : Could not find Windows Runtime type 'Microsoft.Management.Deployment.PackageMatchField'.
At line:1 char:1
+ import-module .\Microsoft.WinGet.Client.psd1 -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

Steps to reproduce

  1. Spin up a new VM and install Windows 11
  2. Update all apps through Microsoft Store
  3. Install all updates through Windows update
  4. Verify that Winget is v1.4.10173
  5. Install Microsoft.Powershell (v7.3.1 for me)
  6. Install Microsoft.VCRedist.2015+.x64 (as specified here)
  7. Download the Powershell module for winget from the releases
  8. import the module and run Get-WingetPackage

Expected behavior

Get-WingetPackage returns a list of all installed packages

Actual behavior

Get-WingetPackage returns Get-WinGetPackage: Exception has been thrown by the target of an invocation.

Environment

Windows Package Manager v1.4.10173
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.22621.1105
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.19.10173.0

gknutson1 avatar Jan 25 '23 23:01 gknutson1

We're actively working on the PowerShell Module:

  • https://github.com/microsoft/winget-cli/pull/2871

This is very much in a preview state.

denelon avatar Jan 26 '23 18:01 denelon

@denelon Any progress on making the module work on PS 5.1?

kborowinski avatar Jul 16 '23 00:07 kborowinski

Any progress on making the module work on PS 5.1?

It could be a notable change in installing application updates remotely with command prompt...

George J.

gcapnias avatar Nov 02 '23 15:11 gcapnias

Since the current preview version does not work on PowerShell 5.1, is it possible to mark it as PowerShell 7.x compatible only?

zbalkan avatar Nov 02 '23 16:11 zbalkan

We're working on Repair-WinGetPackageManager currently so it can be used in Windows PowerShell to install the client. Once that's released, we'll start looking at the other cmdlets. We didn't want to block Windows PowerShell users from being able to leverage the repair cmdlet.

denelon avatar Nov 13 '23 18:11 denelon

What's the update for PS 7

RayyanNafees avatar Feb 02 '24 14:02 RayyanNafees