损坏的包管理器?无法找到模块提供程序 (PowerShellGet)

Corrupt PackageManager? Unable to find module providers (PowerShellGet)

这是一个常见错误,我在网上找到的常见解决方案都没有解决。

无法 运行 Get-PsRepository、Install-Module 和相关 (OneGet?) 命令,除非它们抛出“无法找到模块提供程序 (PowerShellGet)”错误。这似乎是 NuGet packagemanager 模块的问题,但我不知道如何恢复。安装的包提供程序似乎有效

症状模式:
C:> [Net.ServicePointManager]::安全协议

Tls12

获取 PSRepository

PackageManagement\Get-PackageSource : Unable to find module providers (PowerShellGet).
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet.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

注册-PSRepository -默认-详细

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.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  

安装模块 PowerShellGet -Force

PackageManagement\Install-Package : Unable to find module providers (PowerShellGet).
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet.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

事实:
Windows 10 (1903)
Powershell 5.1.18362.1171
运行 PowerShell 作为管理员 不在代理后面
可以访问 https://www.powershellgallery.com/api/v2
可以访问 nuget.org
`[Net.ServicePointManager]::SecurityProtocol = Tls12
FIPS 已禁用 (HKLM\System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy\Enabled DWORD=0)
Get-PackageProvider 仅显示 NuGet 2.8.5.208
PowerShellGet 版本为 1.0.0.1 ;当尝试使用 Install-Module PowerShellGet -Force 强制安装 sxs 时,我得到相同的结果:PackageManagement\Install-Package:无法找到模块提供程序 (PowerShellGet)。

我们遇到了同样的问题。发现这个线程没有解决方案。但我进一步挖掘了一下,在出现这个问题的计算机上,我们发现安装了 PackageManagement 1.4.7 版。 删除后一切开始正常工作。我还没有找到这个东西是如何安装的。似乎是来自 Microsoft 的合法 powershell 模块,但它与 'normal' PowershellGet 模块交互并且似乎破坏了它。 对于我们来说,它位于 %USERPROFILE%/document/WindowsPowershell/Modules。 此 %USERPROFILE% 是公司 OneDrive 也毫无价值。

编辑:Microsoft 已修复此问题:https://github.com/PowerShell/vscode-powershell/issues/3432

没有足够的代表发表评论。

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

我在个人资料的 %USERPROFILE%/documents 中遇到了与包管理相同的问题。当我在这台新机器上安装 VScode 和 Powershell 扩展时,文件日期匹配。

从模块中删除文件夹暂时解决了问题。