当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] PowerShell:修复 - 无法解析包源

作者:精品下载站 日期:2024-12-14 22:02:07 浏览:13 分类:玩电脑

PowerShell:修复 - 无法解析包源


在 PowerShell 中修复错误“无法解析包源‘https://www.powershellgallery.com/api/v2’,请更新 PowerShell 客户端以使用 TLS1.2 版本。

[玩转系统] PowerShell:修复 - 无法解析包源

尝试使用 PowerShell 终端 Find-Module PSWIndowsUpdate 在 PowerShell 库上查找模块时,如果抛出如下所示的异常,则可能是由于 TLS 版本旧版本所致。

WARNING: Unable to resolve package source ‘https://www.powershellgallery.com/api/v2’.
PackageManagement\Find-Package : No match was found for the specified search criteria and module name ‘PSWindowsUpdate’. 
Try Get-PSRepository to see all available registered module repositories.

At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet.0.0.1\PSModule.psm1:1397 char:3
+ PackageManagement\Find-Package @PSBoundParameters | Microsoft …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power…ets.FindPackage:FindPackage) [Find-Package], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage

在本文中,我们将讨论如何修复 PowerShell 中的无法解析包源“https://www.powershellgallery.com/api/v2”错误。

解决 - 无法解析包源

如果 Windows 操作系统使用旧版或旧版 TLS,则在尝试在 PowerShell Gallary 上查找模块时可能会引发异常。

要在 PowerShell 库中查找或下载该模块,需要更新版本的 TLS。使用以下 PowerShell 脚本检查安全协议。

[Net.ServicePointManager]::SecurityProtocol

上述 PowerShell 脚本将返回 TLS 版本。

在 PowerShell 中,要修复无法解析包源‘https://www.powershellgallery.com/api/v2’,请更新安全协议以使用更新版本的 Tls。

运行以下 PowerShell 脚本将 Tls1.2 设置为安全协议。

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

上述 PowerShell 脚本使用 [Net.SecurityProtocolType]::Tls12 设置 TLS1.2 版本

如果您尝试运行命令 Find-Module PSWindowsUpdate ,它将返回如下结果

[玩转系统] PowerShell:修复 - 无法解析包源

结论

我希望上面关于如何解决尝试查找模块或从 PowerShell 库下载模块时无法解析包源错误的文章对您有所帮助。

旧版本的 TLS 1.0 和 TLS1.1 已弃用,因此如果 Windows 操作系统使用旧版本,则需要更新到 TLS1.2 或更高版本。

您可以在 ShellGeek 主页上找到有关 PowerShell Active Directory 命令和 PowerShell 基础知识的更多主题。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯