无法在更新模块上找到存储库 [英] Unable to find repository on Update-Module

查看:48
本文介绍了无法在更新模块上找到存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Windows 10 和 Powershell 5.1

Get-PSRepository 有结果:

<块引用>

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

而更新模块返回错误

<块引用>

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

知道如何修复它吗?

解决方案

TL;DR

看起来像在 PowerShell 中注册的 PSGallery 存储库的 URL 用于指向 https://www.powershellgallery.com/api/v2/ 但它已更改为 https://www.powershellgallery.com/api/v2 在某些时候(注意末尾缺少正斜杠).

λ Get-PSRepository名称 InstallationPolicy SourceLocation---- ------------------ --------------PSGallery 不受信任 https://www.powershellgallery.com/api/v2

从旧 URL 安装的任何模块现在都无法更新.从 PowerShell 库重新安装它们将更新存储库 URL,允许模块正常更新.您可以使用以下命令重新安装指向旧 URL 的所有模块:

Get-InstalledModule `|?{ $_.Repository -eq 'https://www.powershellgallery.com/api/v2/' } `|% { 安装包 -Name $_.Name -Source PSGallery -Force -AcceptLicense }

全面运行

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

<块引用>

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 产生:

名称 InstallationPolicy SourceLocation---- ------------------ --------------PSGallery 可信 https://www.powershellgallery.com/api/v2

所以看起来存储库在那里,除了,也许不是.注意尾部的正斜杠.可能是 Install-Package 正在寻找具有与该字符串完全匹配的 SourceLocation 的存储库?让我们尝试更改 PSGallery 的 SourceLocation:

Set-PSRepository -Name PSGallery -SourceLocation https://www.powershellgallery.com/api/v2/-InstallationPolicy Trusted

<块引用>

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

好吧,那没用.看起来 PSGallery 存储库为了您的安全而受到保护.

让我们尝试添加不同的存储库并更新模块:

Register-PSRepository -Name PSGallery1 -SourceLocation https://www.powershellgallery.com/api/v2/-InstallationPolicy Trusted更新模块 -名称纠缠 -Force

看,没有错误.它有效!

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

Get-InstalledModule |选择名称、存储库 |FT -自动调整大小名称库---- ----------7Zip4Powershell PSGalleryAWSPowerShell PSGallerycChoco PSGallery1dbatools PSGalleryDLMAutomation PSGallery1InvokeBuild PSGallery1Microsoft.PowerShell.Archive PSGallery1包管理 PSGalleryPester PSGallery1豪华的 git PSGallery1powershell-yaml PSGallery1PowerShellGet PSGalleryPowerUpSQL PSGallery1psake PSGallery1PsHosts PSGallery1psTrustedHosts PSGallery1反向DSC PSGallery1见壳牌 PSGallery1SqlServer PSGallery1TunableSSLValidator PSGallery1xSmbShare PSGallery1xWebAdministration PSGallery1

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

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

Get-InstalledModule `|?{ $_.Repository -eq 'PSGallery1' } `|% { 安装包 -Name $_.Name -Source PSGallery -Force -AcceptLicense }

再次运行 Get-InstalledModule 会产生:

名称存储库---- ----------7Zip4Powershell PSGalleryAWSPowerShell PSGallerycChoco PSGallerydbatools PSGalleryDLMAutomation PSGalleryInvokeBuild PSGalleryMicrosoft.PowerShell.Archive PSGallery包管理 PSGallery纠缠 PSGallery豪华的 git PSGallerypowershell-yaml PSGalleryPowerShellGet PSGalleryPowerUpSQL PSGallerypsake PSGalleryPsHosts PSGallerypsTrustedHosts PSGalleryReverseDSC PSGallery见壳PSGallerySqlServer PSGalleryTunableSSLValidator PSGalleryxSmbShare PSGalleryxWebAdministration PSGallery

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

Unregister-PSRepository PSGallery1更新模块 -名称纠缠 -Force

成功!模块更新无误.

我不确定这里出了什么问题,PSGallery 存储库的 URL 或 Install-Package,但重新安装从旧 URL 安装的所有模块似乎可以解决所有问题.

I'm using Windows 10 and Powershell 5.1

Get-PSRepository has result :

PSGallery Untrusted https://www.powershellgallery.com/api/v2

whereas Update-Module returns error

PackageManagement\Install-Package : Unable to find repository 'https://www.powershellgallery.com/api/v2/'. Use Get-PSRepository to see all available repositories. At 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

Any idea of how to fix it?

解决方案

TL;DR

It looks like the URL for the PSGallery repository registered in PowerShell used to point to https://www.powershellgallery.com/api/v2/ but it was changed to https://www.powershellgallery.com/api/v2 at some point (note the missing forward slash at the end).

λ  Get-PSRepository

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Untrusted            https://www.powershellgallery.com/api/v2

Any modules installed from the old URL are now failing to update. Reinstalling them from PowerShell gallery will update the repository URL, allowing the modules to be updated normally going forward. You can use the following command to reinstall all modules pointing to the old URL:

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

The full run down

I have run into this incredibly annoying issue myself. From the error message we can see a couple of things:

PackageManagement\Install-Package : Unable to find repository 'https://www.powershellgallery.com/api/v2/'

  1. PowerShellGet\Update-Module ultimately passes the buck to PackageManagement\Install-Package
  2. It is looking for a repository at 'https://www.powershellgallery.com/api/v2/'

Running Get-PSRepository on my machine yields:

Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Trusted              https://www.powershellgallery.com/api/v2

So it looks like the repository is there, except, maybe it isn't. Take note of the trailing forward slash. Could it be that Install-Package is looking for a repository with a SourceLocation that exactly matches that string? Let's try changing the SourceLocation for PSGallery:

Set-PSRepository -Name PSGallery -SourceLocation https://www.powershellgallery.com/api/v2/ -InstallationPolicy Trusted

PackageManagement\Set-PackageSource : The PSGallery repository has pre-defined locations. The 'Location, NewLocation or SourceLocation' parameter is not allowed, try again after removing the 'Location, NewLocation or SourceLocation' parameter. At 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], Exception + FullyQualifiedErrorId : ParameterIsNotAllowedWithPSGallery,Add-PackageSource,Microsoft.PowerShell.PackageManagement.Cmdlets.SetPackageSource

Well, that didn't work. Looks like the PSGallery repository is protected for your safety.

Let's trying adding a different repository and updating a module:

Register-PSRepository -Name PSGallery1 -SourceLocation https://www.powershellgallery.com/api/v2/ -InstallationPolicy Trusted
Update-Module -Name pester -Force

Look, no error. It works!

Here is the interesting thing, if I pull up a list of installed modules I find a mix of repositories:

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

Look at all those modules installed form PSGallery1 which is associated with https://www.powershellgallery.com/api/v2/! Prior to just now, there has never been a repository on my machine called PSGallery1; every module I have ever installed has been from PSGallery. My guess is that the PSGallery repository used to point to https://www.powershellgallery.com/api/v2/ and at some point, intentionally or not, it was changed to https://www.powershellgallery.com/avp/v2; breaking Update-Module for any modules installed from the previous URL. I suspect that if I reinstall the modules using Install-Package from the updated PSGallery repository everything will resolve itself and I can remove the PSGallery1 repository.

Let's update all the modules that were deployed from the old URL (PSGallery1):

Get-InstalledModule `
| ? { $_.Repository -eq 'PSGallery1' } `
| % { Install-Package -Name $_.Name -Source PSGallery -Force -AcceptLicense }

Running Get-InstalledModule again yields:

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

Great! Now let's try removing the PSGallery1 repository and updating a module:

Unregister-PSRepository PSGallery1
Update-Module -Name pester -Force

Success! The module updated without error.

I'm not sure what is broken here, the URL for the PSGallery repository or Install-Package, but reinstalling all modules that were installed from the old URL seems to fix everything.

这篇关于无法在更新模块上找到存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆