我正在使用powershell脚本下载并执行一个文件,但由于一段时间后,我得到了一个无法创建ssl/tsl安全通道。
$down = New-Object System.Net.WebClient;
$url = 'url';
$file = 'file';
$down.DownloadFile($url,$file);
$exec = New-Object -com shell.application;
$exec.shellexecute($file);
exit; 发布于 2020-06-15 21:43:05
应该启用TLS 1.2才能使其正常工作。在PowerShell中,您可以通过运行以下代码找出您的系统支持哪些协议:
[Enum]::GetNames([Net.SecurityProtocolType]) -contains 'Tls12'如果结果为True,则您的系统支持TLS 1.2。您可以通过运行以下命令找出正在使用的协议:
[System.Net.ServicePointManager]::SecurityProtocol.HasFlag([Net.SecurityProtocolType]::Tls12)如果结果为True,则使用的是TLS 1.2。但是,您可以使用以下命令显式添加TLS 1.2:
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12这应该可以解决这些问题。
发布于 2018-04-12 23:48:04
您连接的站点可能需要TLS 1.2,而powershell默认使用TLS 1.0 (如果我没记错的话)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$down = New-Object System.Net.WebClient
$url = 'https://github.com/mpdairy/posh.git'
$file = 'C:\ExistingDirectory\test.git'
$down.DownloadFile($url,$file)
$exec = New-Object -com shell.application
$exec.shellexecute($file)
exit如果不使用Tls 1.2,我会得到这样的错误:
Exception calling "DownloadFile" with "2" argument(s): "The request was aborted: Could not create SSL/TLS
secure channel."
At line:1 char:1
+ $down.DownloadFile($url,$file)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException发布于 2019-01-11 19:46:37
我在Windows服务器上安装Wiki.js时也遇到了同样的错误。问题是ps1脚本包含了TLS1.1作为后备。对于任何其他powershell安装,都可以更改以下步骤
来解决这个问题;
iex ((新的-对象System.Net.WebClient).DownloadString('https://wiki.js.org/install.ps1'))
发自:
Net.ServicePointManager::SecurityProtocol = "tls12,tls11,tls“
至:
运行命令"iex .\install.ps1"“,Net.ServicePointManager::SecurityProtocol =”tls12“
现在一切都好了。
https://stackoverflow.com/questions/49800534
复制相似问题