警告:无法找到模块存储库

53
我尝试在已激活的 Windows Server 2016 Standard 上安装 Docker。我执行了 “Install-Module -Name DockerMsftProvider -Repository PSGallery -Force”,但失败了。它建议找不到 PSGallery。我执行了 "Get-PSRepository"
错误信息如下:

WARNING: 无法找到模块存储库

我尝试了3种解决方法,但都没有成功。
  1. 我成功地执行了 Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Verbose -Force

  2. 我成功地安装了 chocolatey。

  3. 我执行了 "powershell Register-PSRepository -Name "PSGallery" –SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted",但失败了。它要求我使用 "Register-PSRepository -Default"

我尝试了 "powershell Register-PSRepository -Default -Name "PSGallery" –SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted",但仍然失败。
请问我该如何解决这个问题?

同样的问题:https://github.com/OneGet/oneget/issues/183 - Vadzim
6个回答

81

随着 自2020年4月起停用PowerShell Gallery的TLS 1.0和1.1, cmdlets Update-Module和Install-Module出现了故障。因此,根据这篇文章,需要执行一些命令才能使它们重新启动:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 
Install-Module PowerShellGet -RequiredVersion 2.2.4 -SkipPublisherCheck

如果仍然无法解决问题,那么运行以下命令:
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Register-PSRepository -Default -Verbose
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted

最近在NuGet.org上也弃用了TLS 1.0和1.1: nuget.org deprecated TLS 1.0 and 1.1这也是之前宣布的

4
未找到名称为“PSGallery”的存储库。 - Sauron

35

对我来说,只需运行Register-PSRepository -Default(不需要任何其他参数)即可。之后,库已成功注册:

PS C:\Windows\system32> Get-PSRepository

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

22

我的问题是缺少代理配置

以下是评论中提供的最佳解决方案: https://www.zerrouki.com/working-behind-a-proxy/
感谢@Vadzim


在 PowerShell 中打开个人资料

PS> notepad $PROFILE

这将使用您的配置文件设置打开记事本,如果不存在则会创建。
然后添加:

[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://webproxy.yourCompany.com:PORT')
[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

我的本地代理已经设置,但是无法工作。 稍后在Docker中也遇到了同样的问题,=>

> PS> [Environment]::SetEnvironmentVariable("HTTP_PROXY", http://username:password@proxy:port/", [EnvironmentVariableTarget]::Machine)

然后重新启动 Docker 服务


1
还可以看一下 https://www.zerrouki.com/working-behind-a-proxy/ 和 https://spaghettidba.com/2017/12/19/recovering-the-psgallery-repository-behind-a-corporate-proxy/。 - Vadzim
1
引用更好的部分对你的回答会有益处。 - Vadzim
我见过很多人提到这个答案,但我的家用电脑上却出现了错误,而且没有代理。 - KERR
1
对于PowerShell Core v7,以下是有效的代码: [System.Net.Http.HttpClient]::DefaultProxy = New-Object System.Net.WebProxy('http://127.0.0.1:8888', $true, @(";*.bypassdomain.com")) - Janis Veinbergs
谢谢!这正是我所缺少的。 - MKANET

7

我收到了类似的信息。我运行了Register-PSRepository -default,然后它成功注册了。接着我运行了Set-PSRepository -Name PSGallery -InstallationPolicy Trusted。我没有结合这两个命令,但是它起作用了。

我试图像在Exchange Online上一样传递凭据给代理服务器,但是失败了,我花费了一个多小时。最后我断开连接,使用了我们的访客WiFi。


0

还有一件事情没有提到。 你确实需要运行

notepad $profile

并复制粘贴此部分,更改您的代理详细信息:

[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://webproxy.yourCompany.com:PORT')
[system.net.webrequest]::defaultwebproxy.credentials =  System.Net.CredentialCache]::DefaultNetworkCredentials
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

如果您打开了HTTPS检查功能,您可能希望将中间人证书添加到“受信任的根证书颁发机构”。

0
配置正确的 TLS 版本导致了以下错误:
PS /> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12                                  
PS /> Install-Module PowerShellGet -RequiredVersion 2.2.4 -SkipPublisherCheck
Install-Package: No match was found for the specified search criteria and module name 'PowerShellGet'. Try Get-PSRepository to see all
available registered module repositories.
PS /> Get-PSRepository -Verbose
WARNING: Unable to find module repositories.

如果您在公司代理服务后面工作,可能需要向 CA 添加信任。

cp my.crt /usr/local/share/ca-certificates/
update-ca-certificates

在更新了我们的信任存储后,我们可以查询powershell仓库。

PS /> Get-PSRepository

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接