如何使用 PowerShell 更改 TLS 版本?


眾所周知的傳輸層安全性 (TLS) 在使用 URI 命令(如 Invoke−WebRequestInvoke−Restmethod 命令)和包命令(如 Find−PackageInstall−Package)時十分重要,因為這些命令在 Internet 上進行互動,並且 PowerShell 需要 TLS1.2 版本才能進行互動。

使用較低版本的 TLS 時,可能會出現以下錯誤。

WARNING: Unable to download the list of available providers. Check your internet connection.
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
Find-Package : No match was found for the specified search criteria and package name

若要解決上述錯誤,我們需要更改 TLS 版本。若要檢查現有 TLS 版本,可以使用以下命令:

PS C:\> [Net.ServicePointManager]::SecurityProtocol
Ssl3, Tls

若要將 TLS 版本更改為 1.2,可以使用以下命令。

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

更新於: 2021 年 1 月 25 日

3K+ 次瀏覽

開啟您的 職業生涯

完成課程以獲得認證

開始
廣告
© . All rights reserved.