无法在Update-Module上找到存储库

Afs*_*var 12 powershell

我正在使用Windows 10和Powershell 5.1

Get-PSRepository有结果:

PSGallery不受信任 https://www.powershellgallery.com/api/v2

而Update-Module返回错误

PackageManagement\Install-Package:无法找到存储库' https://www.powershellgallery.com/api/v2/ '.使用Get-PSRepository查看所有可用的存储库.在C:\ Program Files\WindowsPowerShell\Modules\powershellget\2.0.1\PSModule.psm1:13000 char:20 + ... $ sid = PackageManagement\Install-Package @PSBoundParameters + ~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:ObjectNotFound :( Microsoft. Power .... InstallPackage:InstallPackage)[Install-Package],Ex ception + FullyQualifiedErrorId:SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

知道怎么解决它?

Jas*_*oyd 23

TL; DR

看起来好像在PowerShell中注册的PSGallery存储库的URL曾经指向https://www.powershellgallery.com/api/v2/,但在某些情况下已更改为https://www.powershellgallery.com/api/v2点(注意末尾缺少的正斜杠)。

?  Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2
Run Code Online (Sandbox Code Playgroud)

从旧URL安装的所有模块现在都无法更新。从PowerShell库中重新安装它们将更新存储库URL,从而允许正常情况下对模块进行更新。您可以使用以下命令来重新安装所有指向旧URL的模块:

Get-InstalledModule `
| ? { $_.Repository -eq 'https://www.powershellgallery.com/api/v2/' } `
| % { Install-Package -Name $_.Name -Source PSGallery -Force -AcceptLicense }
Run Code Online (Sandbox Code Playgroud)

全力以赴

我自己遇到了这个令人难以置信的烦人的问题。从错误消息中,我们可以看到以下几点:

PackageManagement \ Install-Package:无法找到存储库' https://www.powershellgallery.com/api/v2/ '

  1. PowerShellGet\Update-Module 最终把钱推给了 PackageManagement\Install-Package
  2. 它正在' https://www.powershellgallery.com/api/v2/ ' 寻找存储库

Get-PSRepository在我的机器上运行会产生:

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Trusted              https://www.powershellgallery.com/api/v2
Run Code Online (Sandbox Code Playgroud)

因此,看起来存储库在那里,除了,也许不是。注意尾随的前斜杠。难道Install-Package是在寻找一个SourceLocation与该字符串完全匹配的存储库?让我们尝试更改SourceLocationPSGallery的:

Set-PSRepository -Name PSGallery -SourceLocation https://www.powershellgallery.com/api/v2/ -InstallationPolicy Trusted
Run Code Online (Sandbox Code Playgroud)

PackageManagement \ Set-PackageSource:PSGallery存储库具有预定义的位置。不允许使用“ Location,NewLocation或SourceLocation”参数,请在删除“ Location,NewLocation或SourceLocation”参数后重试。在C:\ Program Files \ WindowsPowerShell \ Modules \ PowerShellGet \ 2.0.4 \ PSModule.psm1:11768 char:17 + ... $ null = PackageManagement \ Set-PackageSource @PSBoundParameters + ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + CategoryInfo:InvalidArgument:(https://www.pow...ery.com/api/v2/:String)[Set-PackageSource],异常+ FullyQualifiedErrorId:ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.SetPackageSource

好吧,那没有用。看起来PSGallery存储库出于安全考虑受到保护

让我们尝试添加其他存储库并更新模块:

Register-PSRepository -Name PSGallery1 -SourceLocation https://www.powershellgallery.com/api/v2/ -InstallationPolicy Trusted
Update-Module -Name pester -Force
Run Code Online (Sandbox Code Playgroud)

看,没错。有用!

这是有趣的事情,如果我列出了已安装模块的列表,则会发现混合存储库:

Get-InstalledModule | Select Name, Repository | FT -AutoSize

Name                         Repository
----                         ----------
7Zip4Powershell              PSGallery 
AWSPowerShell                PSGallery 
cChoco                       PSGallery1
dbatools                     PSGallery 
DLMAutomation                PSGallery1
InvokeBuild                  PSGallery1
Microsoft.PowerShell.Archive PSGallery1
PackageManagement            PSGallery 
Pester                       PSGallery1
posh-git                     PSGallery1
powershell-yaml              PSGallery1
PowerShellGet                PSGallery 
PowerUpSQL                   PSGallery1
psake                        PSGallery1
PsHosts                      PSGallery1
psTrustedHosts               PSGallery1
ReverseDSC                   PSGallery1
SeeShell                     PSGallery1
SqlServer                    PSGallery1
TunableSSLValidator          PSGallery1
xSmbShare                    PSGallery1
xWebAdministration           PSGallery1
Run Code Online (Sandbox Code Playgroud)

查看从PSGallery1安装的所有与https://www.powershellgallery.com/api/v2/相关联的模块!在此之前,我的计算机上从未存在过名为PSGallery1的存储库。我曾经安装的每个模块都来自PSGallery。我的猜测是,PSGallery存储库曾经指向https://www.powershellgallery.com/api/v2/,并且在某些时候(有意或无意)将其更改为https://www.powershellgallery.com/avp/ v2 ; 破坏Update-Module从上一个URL安装的所有模块。我怀疑如果使用Install-Package更新的PSGallery存储库中的模块重新安装模块,一切都会自行解决,并且可以删除PSGallery1存储库。

让我们更新从旧URL(PSGallery1)部署的所有模块:

Get-InstalledModule `
| ? { $_.Repository -eq 'PSGallery1' } `
| % { Install-Package -Name $_.Name -Source PSGallery -Force -AcceptLicense }
Run Code Online (Sandbox Code Playgroud)

Get-InstalledModule再次运行将产生:

Name                         Repository
----                         ----------
7Zip4Powershell              PSGallery
AWSPowerShell                PSGallery
cChoco                       PSGallery
dbatools                     PSGallery
DLMAutomation                PSGallery
InvokeBuild                  PSGallery
Microsoft.PowerShell.Archive PSGallery
PackageManagement            PSGallery
Pester                       PSGallery
posh-git                     PSGallery
powershell-yaml              PSGallery
PowerShellGet                PSGallery
PowerUpSQL                   PSGallery
psake                        PSGallery
PsHosts                      PSGallery
psTrustedHosts               PSGallery
ReverseDSC                   PSGallery
SeeShell                     PSGallery
SqlServer                    PSGallery
TunableSSLValidator          PSGallery
xSmbShare                    PSGallery
xWebAdministration           PSGallery
Run Code Online (Sandbox Code Playgroud)

大!现在,让我们尝试删除PSGallery1存储库并更新模块:

Unregister-PSRepository PSGallery1
Update-Module -Name pester -Force
Run Code Online (Sandbox Code Playgroud)

成功!模块已更新,没有错误。

我不确定PSGallery存储库或URL的损坏之处Install-Package,但是重新安装从旧URL安装的所有模块似乎可以解决所有问题。

  • 在 PowerShell 5.1 桌面上,-AcceptLicense 参数未知。删除它,效果很好。名称 值 ---- ----- PSVersion 5.1.19041.1023 PSEdition 桌面 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 (3认同)

小智 9

在尝试了各种方法之后,强制重新安装 NuGet 包提供程序似乎已经为我解决了 Update-Module 的问题。

在提升的 PowerShell 会话中执行此操作:

Install-PackageProvider Nuget –Force
Run Code Online (Sandbox Code Playgroud)

作为参考,当我获得最大成功时我就在这里:https : //docs.microsoft.com/en-us/powershell/scripting/gallery/installing-psget


Hen*_*sen 7

我遇到了同样的问题并发现了这个问题。我尝试了 Jason Boyd(上图)所写的所有内容,但没有奏效。

搜索更多并找到此链接https://community.spiceworks.com/topic/2265662-powershell-get-download-problem

它说TLS 1.0可能是罪魁祸首。它建议运行

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 
Run Code Online (Sandbox Code Playgroud)

在那之后,我能够更新我的包。


Mik*_*ell 1

我对 Windows Powershell 5.1.17134.407 也有同样的问题,并且也在同一台机器上的 PowerShell 6.1 上进行了测试。Update-Module 可按预期与 PowerShell 6.1 配合使用,并在 Windows PowerShell 和 PowerShell 中使用相同版本的 PowerShellGet 模块。因此,看起来这个问题是 Windows PowerShell 特有的,无需进一步测试即可猜测,这是在 Windows PowerShell 上运行时 PowerShellGet 模块本身的 Update-Module 代码中的问题。

我没有使用 Update-Module 的解决方案,但作为解决方案,您可以使用 Install-Module 代替 -AllowClobber 参数。它不会像 Update-Module 那样因此错误而失败。而且,至少现在,最终结果将是相同的,因为 Update-Module 实际上只是并排安装新版本与根据我的测试和https://github 安装的任何旧版本。 com/PowerShell/PowerShellGet/issues/213

...

在做了一些进一步的测试后,我碰巧重新启动了我正在测试的系统。重新启动后,Windows PowerShell 5.1 中的 Update-Module 问题已得到解决 - Update-Module 现在可以按预期工作。我不能肯定地说重新启动可以解决这个问题,但现在已经解决了。