我正在使用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;
Run Code Online (Sandbox Code Playgroud)
Ash*_*faq 24
应启用 TLS 1.2 以使其正常工作。在 PowerShell 中,您可以通过运行以下代码找出您的系统支持哪些协议:
[Enum]::GetNames([Net.SecurityProtocolType]) -contains 'Tls12'
Run Code Online (Sandbox Code Playgroud)
如果结果为 True,则您的系统支持 TLS 1.2。您可以通过运行以下命令找出正在使用的协议:
[System.Net.ServicePointManager]::SecurityProtocol.HasFlag([Net.SecurityProtocolType]::Tls12)
Run Code Online (Sandbox Code Playgroud)
如果结果为 True,则正在使用 TLS 1.2。但是,您可以使用以下命令显式添加 TLS 1.2:
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Run Code Online (Sandbox Code Playgroud)
这应该可以解决这些问题。
可能是您所连接的站点需要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
Run Code Online (Sandbox Code Playgroud)
如果不使用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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5983 次 |
| 最近记录: |