7

This is a common error that is not solved by the common solutions I have found on the internet.

Unable to run Get-PsRepository, Install-Module, and related (OneGet?) commands without them throwing the "Unable to find module providers (PowerShellGet)" error. This appears to be an issue with the NuGet packagemanager module but I do not know how to recover. The package provider installed appears valid

Symptom patterns:
C:> [Net.ServicePointManager]::SecurityProtocol

Tls12

Get-PSRepository

PackageManagement\Get-PackageSource : Unable to find module providers (PowerShellGet).
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4496 char:31
+ ... ckageSources = PackageManagement\Get-PackageSource @PSBoundParameters
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power...etPackageSource:GetPackageSource) [Get-PackageSource
   ], Exception
    + FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageSource

Register-PSRepository -Default -Verbose

VERBOSE: PowerShell meta provider initialization failed.
VERBOSE: No match was found for the specified search criteria and provider name 'PowerShellGet'. Try
'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.
PackageManagement\Register-PackageSource : Unable to find module providers (PowerShellGet).
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4211 char:17
+ ...     $null = PackageManagement\Register-PackageSource @PSBoundParamete ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power...erPackageSource:RegisterPackageSource) [Register-Pac
   kageSource], Exception
    + FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource  

Install-Module PowerShellGet -Force

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], Exception
    + FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

Facts:
Windows 10 (1903)
Powershell 5.1.18362.1171
Running PowerShell as Administrator Not behind a proxy
Have access to https://www.powershellgallery.com/api/v2
Have access to nuget.org
`[Net.ServicePointManager]::SecurityProtocol = Tls12
FIPS is disabled (HKLM\System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy\Enabled DWORD=0)
Get-PackageProvider shows only NuGet 2.8.5.208
PowerShellGet version is 1.0.0.1 ; when trying force a sxs install with Install-Module PowerShellGet -Force I get the same: PackageManagement\Install-Package : Unable to find module providers (PowerShellGet).

GeneralZod
  • 109
  • 1
  • 8
  • I appear to be getting the same error, were you able to figure this out? – aolszowka Jan 08 '21 at 00:08
  • 1
    FWIW I created a brand new Windows 1909 VM with nothing on it and attempted to restore the packages and encountered a similar failure in that environment. Luckily I was able to leverage PowerShell Core which was unaffected. If you open up a support ticket with Microsoft let me know so I can follow along there as well. – aolszowka Jan 10 '21 at 13:07

3 Answers3

11

We encountered the same problem. Found this thread without a solution. But I dug a bit further and on the computer that had this problem we found version 1.4.7 of PackageManagement installed. After removing this folder everything started working normally. I have not found how this thing got installed. Seems like a legit powershell module from Microsoft but it's interacting with the 'normal' PowershellGet module and seems to break it. For us it was located in the %USERPROFILE%/documents/WindowsPowershell/Modules. Also worth nothing that this %USERPROFILE% was a corporate OneDrive.

Edit: Microsoft have fixed this issue: https://github.com/PowerShell/vscode-powershell/issues/3432

MyuFoxy
  • 38
  • 5
elangelo
  • 148
  • 2
  • 6
  • 1
    I ended up in the same situation. A Windows 10 1909 machine, with %USERPROFILE%/document being a corporate OneDrive. Moving PackageManagement out of /WindowsPowerShell/ changed Get-PSRepository's output from nothing to PSGallery. Thanks! – tmcg Mar 01 '21 at 21:35
  • This was exactly the same issue. I suspect this is because PowerShell 7 dumped it into this location (possibly Visual Studio Code when it prompt to update?) – aolszowka Mar 01 '21 at 22:09
  • Thank you! Removing the 1.4.7 package management folder from my document folder immediately (once i started a new shell) solved the issue! My documents folder is on a corporate onedrive, but i think the real culprit may be vscode because it begs for an upgrade if you leave it with the old PM - i totally forgot about that and I think that's what caused the problem originally. – GeneralZod Mar 09 '21 at 22:08
  • I would also like to sincerely thank you. Nothing in the error messages pointed me to a conflicting personal module. After removal of the offending module, all worked again. Thanks again! – BHall Mar 30 '21 at 17:01
  • Holy cow, I just spent like 5 hours debugging this and your answer saved me. Sincere thanks! – Bassinator May 19 '21 at 15:26
  • I just wasted a whole workday trying to find the answer to this problem and then I came across this solution... No idea how it appeared there but exact same symptoms... corporate OneDrive.... – NotoriousPyro Jun 11 '21 at 15:30
  • Can you please explain, how to fix the issue? – sssreddy Nov 09 '21 at 22:58
  • Microsoft have since patched it https://github.com/PowerShell/vscode-powershell/issues/3432 @sssreddy – NotoriousPyro Mar 31 '22 at 06:53
3

Not enough Rep to comment.

I ended up in the same situation. A Windows 10 1909 machine, with %USERPROFILE%/document being a corporate OneDrive. Moving PackageManagement out of /WindowsPowerShell/ changed Get-PSRepository's output from nothing to PSGallery. Thanks! – tmcg Mar 1 at 21:35 This was exactly the same issue. I suspect this is because PowerShell 7 dumped it into this location (possibly Visual Studio Code when it prompt to update?) – aolszowka Mar 1 at 22:09

I encountered the same issue with packagemanagement in %USERPROFILE%/documents on my personal profile. The file dates matched when I installed VScode and the Powershell Extensions on this new machine.

Removing the folder from modules corrected the issue for the time being.

Redsloth55
  • 61
  • 2
  • 1
    This is what we are seeing as well, this is related to VS Code's offer to upgrade `PackageManagement` which we believe leads to this issue. – aolszowka Mar 11 '21 at 13:56
  • Holy cow, I just spent like 5 hours debugging this and your answer saved me. Sincere thanks! – Bassinator May 19 '21 at 15:26
0

In addition to removing %USERPROFILE%/Documents/WindowsPowershell/Modules folder, I also found that putting the package manger locally helped powershell.exe -NoLogo -NoProfile -Command 'Save-Module PackageManagement -MinimumVersion 1.4.7 -LiteralPath ""C:\Program Files\WindowsPowerShell\Modules\""' thanks to itsho here https://github.com/PowerShell/vscode-powershell/issues/2824#issuecomment-750902181

The cause is due to the %USERPROFILE%/Documents folder being on a OneDrive and module-install keeps installing the PackageManagement module to user documents by default ignoring PSModulePath, even had the OneDrive location removed/changed.

This my module path from running PS inside vscode identifying info removed:

$env:PSModulePath -split ';'
C:\Users\{myUsername}\OneDrive - {myCompanyName}\{company}\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

There are more things that can be done to fix this from happening again discussed here https://github.com/PowerShell/PowerShell/issues/15552#issuecomment-1002708799 Like setting the documents folder to local and off OneDrive like shown here https://support.microsoft.com/en-us/topic/configuration-of-the-my-documents-folder-dfd9a90d-8f80-18d6-e7cc-f1566fc3b10b

I followed these steps for now.

  1. In explorer to the left under quick access right click Documents, and then click Properties.
  2. Change to the location tab in the configuration box and type the new path to the Documents folder, I used the local one
  3. Click No so the existing files do not move and still can be accessed by going into OneDrive. I also added another quick access folder for my OneDrive location, but that is up to you. Note: This effects other programs as well like the default save location for PowerPoint. You'll need to be mindful that you don't save something local thinking it will be backed up to OneDrive.

My module paths after the change:

$env:PSModulePath -split ';'
C:\Users\{myUsername}\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

Another workaround could be to have OneDrive keep the files local.

  1. Navigate to %USERPROFILE%/Documents
  2. Right click WindowsPowershell and select "Always keep on this device". I haven't been able to test this one, but it might be the least impactful way to address this.
MyuFoxy
  • 38
  • 5