【问题标题】:Enable tls1.2 on windows 7 with powershell 2.0在带有 powershell 2.0 的 Windows 7 上启用 tls1.2
【发布时间】:2021-08-16 19:26:18
【问题描述】:

无法在带有 powershell 2.0 的 Windows 7SP1 上启用 TLS1.2:

PS C:\Windows\system32> $PSVersionTable

Name                           Value
----                           -----
CLRVersion                     2.0.50727.8806
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1

我猜 P.Sv2.0 使用的是 .NET v2.0:

PS C:\Windows\system32> $PSVersionTable.CLRVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      50727  8806

PS C:\Windows\system32> [System.Environment]::Version

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      50727  8806

此外,此系统上安装了以下 .NET 版本:

PS C:\Windows\system32> Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name Version, Release -ErrorAction 0 | where { $_.PSChildName -match '^(?!S)\p{L}'} | select Version, Release, PSChildName

Version                           Release                          PSChildName
-------                           -------                          -----------
2.0.50727.5420                                                     v2.0.50727
3.0.30729.5420                                                     v3.0
3.0.4506.5420                                                      Windows Communication Foundation
3.0.6920.5011                                                      Windows Presentation Foundation
3.5.30729.5420                                                     v3.5
4.8.03761                         528049                           Client
4.8.03761                         528049                           Full
4.0.0.0                                                            Client

但是,我无法使用该配置设置 TLSv1.2:

PS C:\Windows\system32> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Exception lors de la définition de « SecurityProtocol » : « Impossible de convertir la valeur Null en type « System.Net.SecurityProtocolType » en raison de valeurs d'énumération non valides. Spécifiez l'une des valeurs d'énumération suivantes et réessayez. Les valeurs d'énumération possibles sont « Ssl3, Tls ». »
Au niveau de ligne : 1 Caractère : 28
+ [Net.ServicePointManager]:: <<<< SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException
PS C:\Windows\system32> [enum]::GetNames([Net.SecurityProtocolType])
Ssl3
Tls
PS C:\Windows\system32> 

编辑 0:@mclayton 将 [Net.ServicePointManager]::SecurityProtocol 设置为 3072 的整数值也不起作用:

PS C:\Windows\system32> [Net.ServicePointManager]::SecurityProtocol = 3072
Exception lors de la définition de « SecurityProtocol » : « Impossible de convertir la valeur « 3072 » en type « System.Net.SecurityProtocolType » en raison de valeurs d'énumérati
on non valides. Spécifiez l'une des valeurs d'énumération suivantes et réessayez. Les valeurs d'énumération possibles sont « Ssl3, Tls ». »
Au niveau de ligne : 1 Caractère : 28
+ [Net.ServicePointManager]:: <<<< SecurityProtocol = 3072
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

你能帮帮我吗?

【问题讨论】:

  • 试试$Protocol = [Enum]::ToObject([System.Net.SecurityProtocolType], 3072); [System.Net.ServicePointManager]::SecurityProtocol = $Protocol
  • @AbrahamZinala 抱歉,我的回复晚了,我无法每天使用这台电脑。将[Net.ServicePointManager]::SecurityProtocol 设置为3072 的整数值也不起作用。请参阅我的 EDIT 0。
  • 请使用完整代码,必要时复制粘贴。为什么不直接升级 .net?
  • @AbrahamZinala 您的 powershell sn-p 有效!非常感谢。顺便说一句:.NET v4.0 已经安装,但 powershell v2.0 仅使用 .NET v2.0。我想我需要将powershell升级到powershell v3.0(至少)能够使用.NET v> = 4.0。您能否将your first comment 转换为答案以便我接受?

标签: powershell windows-7 tls1.2


【解决方案1】:

为了扩展 @Abraham Zinala 的评论,直到 Dot Net Framework 4.5 版(请参阅 https://docs.microsoft.com/en-us/dotnet/api/system.net.securityprotocoltype?view=netframework-4.5),Tls12 枚举值才添加到 System.Net.SecurityProtocolType 枚举中。

您的 PowerShell 2.0 安装使用的版本低于此版本,因此无法解析 [Net.SecurityProtocolType]::Tls12 的值。

你可以做的是使用枚举的整数值:

# assign the magic number to a variable for clarity
$tls12 = 3072;

[Net.ServicePointManager]::SecurityProtocol = $tls12;

【讨论】:

  • 抱歉,我的回复晚了,我无法每天使用这台电脑。将[Net.ServicePointManager]::SecurityProtocol 设置为3072 的整数值也不起作用。请参阅我的 EDIT 0。
  • 我需要升级到 powershell 3 才能使用 .NET v4 吗?
  • 我已经升级到 PS3.0。您的解决方案适用于 PS3.0/.NET4.0
猜你喜欢
  • 1970-01-01
  • 2019-01-09
  • 2016-12-21
  • 2022-01-22
  • 1970-01-01
  • 2023-04-07
  • 1970-01-01
  • 2020-09-29
相关资源
最近更新 更多