Powershell错误,提示图库不可用,请稍后再试

bcs8qyzn  于 2023-03-30  发布在  Shell
关注(0)|答案(3)|浏览(478)

我遇到了这个问题,我无法安装任何模块。即使当我试图注册我得到这个错误。任何解决这个问题的想法,感谢它。

PS C:\Users\abc> Register-PSRepository -Name PSGallery -SourceLocation https://www.powershellgallery.com/api/v2
Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable.  Please try again later.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4095 char:9
+         Get-PSGalleryApiAvailability -Repository $Name
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-PSGalleryApiAvailability], InvalidOperationException
    + FullyQualifiedErrorId : PowerShellGalleryUnavailable,Get-PSGalleryApiAvailability
 
Register-PSRepository : Use 'Register-PSRepository -Default' to register the PSGallery repository.
At line:1 char:1
+ Register-PSRepository -Name PSGallery -SourceLocation https://www.pow ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (PSGallery:String) [Register-PSRepository], ArgumentException
    + FullyQualifiedErrorId : UseDefaultParameterSetOnRegisterPSRepository,Register-PSRepository
 

PS C:\Users\abc> $PSVersionTable

Name                           Value                                                                                                                                                                 
----                           -----                                                                                                                                                                 
PSVersion                      5.1.17134.858                                                                                                                                                         
PSEdition                      Desktop                                                                                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                               
BuildVersion                   10.0.17134.858                                                                                                                                                        
CLRVersion                     4.0.30319.42000                                                                                                                                                       
WSManStackVersion              3.0                                                                                                                                                                   
PSRemotingProtocolVersion      2.3                                                                                                                                                                   
SerializationVersion           1.1.0.1

--添加更多命令

Find-PackageProvider -Name nuget
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
WARNING: Unable to download the list of available providers. Check your internet connection.
Find-PackageProvider : No match was found for the specified search criteria and package name 'nuget'. Try
Get-PackageSource to see all available registered package sources.
At line:1 char:1
+ Find-PackageProvider -Name nuget
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...PackageProvider:FindPackageProvider) [Find-PackagePro
   vider], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvid
   er

注册表似乎已完成,没有任何错误,但没有添加任何内容
一个二个一个一个

tzdcorbm

tzdcorbm1#

尝试强制tls1.2。这解决了大多数powershell库问题
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

8ftvxx2r

8ftvxx2r2#

  • 不是一个真正的解决方案,而是一个供参考的文章。* 现在,当https://www.powershellgallery.com/api/v2中的TLS证书到期时,这似乎也会定期发生。出于某种原因,微软正在努力让证书续订正常工作。

当这种情况发生时,上面提到的解决方案都不会起作用。事实上,当我键入以下内容时,这种情况正在发生... https://github.com/PowerShell/PowerShellGallery/issues/166
要查看问题是否由过期(或无效)的证书引起,只需在浏览器中打开此URL https://www.powershellgallery.com/api/v2,并查看浏览器是否抱怨证书。
如果你只需要让它工作一次,你可以尝试欺骗Powershell忽略无效的证书,如下所示:

[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true};

......但请注意:
a)这是一个不好的做法,你不应该把它作为一个永久的解决方案,因为这会让你暴露在中间人的攻击之下;和
B)这可能对您没有帮助,因为Microsoft人员通常在发生这种情况时禁用PSCallery API。要检查API是否已禁用,请运行:

# Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable.  Please try again later.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4302 char:9
+         Get-PSGalleryApiAvailability -Repository $Name
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Get-PSGalleryApiAvailability], InvalidOperationException
    + FullyQualifiedErrorId : PowerShellGalleryUnavailable,Get-PSGalleryApiAvailability
  • 更新:* 也可以在这里查看PSGallery当前存在的任何问题:* 一个月一次 *
oo7oh9g9

oo7oh9g93#

其实强制tls 12是不足以解决的,但是,仔细阅读到错误信息说:使用“Register-PSRepository -Default”
所以我尝试了:register-psrepository -Default

PS C:\Windows\system32> register-psrepository -Default
PS C:\Windows\system32> get-psrepository

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

它解决了问题。

相关问题