Skip to content

Accepting the prompt to upgrade PackageManagement breaks PowerShell #3432

@NotoriousPyro

Description

@NotoriousPyro

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.

Summary

If I accept the prompt given by VS code on launch to upgrade 'PackageManagement' in PowerShell, it runs this command:

powershell.exe -NoLogo -NoProfile -Command '[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Install-Module -Name PackageManagement -Force -MinimumVersion 1.4.6 -Scope CurrentUser -AllowClobber -Repository PSGallery'

Which seemed like it removed the message in VS code, although not too long ago I was troubleshooting an issue in PowerShell directly, where my main development machine started showing this issue when I tried to install modules like Az.ResourceGraph

PS C:\WINDOWS\system32> Install-Module -Name Az.ResourceGraph
PackageManagement\Install-Package : Unable to find module providers (PowerShellGet).
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], E
   xception
    + FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

It took a while to figure out, in fact it was a stackoverflow question which revealed the problem: https://stackoverflow.com/questions/65482945/corrupt-packagemanager-unable-to-find-module-providers-powershellget/66422362#66422362

The problem appeared to be due to PackageManagement 1.4.7 being installed into C:\Users\ccrawford\OneDrive - Flexera, Inc\Documents\WindowsPowerShell\Modules\PackageManagement

For a while I was confused as to how it got there and why it was breaking my PowerShell 'Install-Module' commands. From the responses I can see others are just as confused as to how this got here...

Although after deleting it I noticed the next time I started VS Code it was asking me to install an 'outdated' package of PackageManagement... knowing well I deleted it. I accepted the prompt and saw it creating this 1.4.7 version, after which PowerShell was broken again - deleting PackageManagement from the above folder is the only way to fix it.

PowerShell Version

PS C:\WINDOWS\system32> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1023
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1023
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Visual Studio Code Version

PS C:\Users\ccrawford> code --version

1.57.1
507ce72a4466fbb27b715c3722558bb15afa9f48
x64

Extension Version

ms-vscode.powershell@2021.5.1
PS C:\Users\ccrawford>  code --list-extensions --show-versions | Select-String powershell


ms-vscode.powershell@2021.6.1

Steps to Reproduce

  1. Accept the prompt
  2. Launch PowerShell
  3. Try to install a module which is not installed

Visuals

No response

Logs

After deleting the offending module:

PS C:\WINDOWS\system32> Install-Module -Name Az.ResourceGraph
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
PS C:\WINDOWS\system32>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions