Powershell 将安全协议设置为 Tls 1.2

Powershell Setting Security Protocol to Tls 1.2

我正在使用这个代码

        $WebClient = New-Object system.net.webclient
        $WebClient.credentials = New-Object System.Net.NetworkCredential -ArgumentList $username, $password
        $WebClient.Proxy = $null
        $WebClient.Headers.Add("COperation","MethodCall")
        $WebClient.Headers.Add("CMethod", "EnumerateInstances")
        $WebClient.Headers.Add("CObject", $NameSpace)
        $WebClient.Headers.Add("Content-Type", "application/xml")
        $System= $WebClient.UploadString($Url, "POST", $EnumMessage)

这个效果很好。我想要做的是将安全协议设置为 Tls1.2 或 Tls1.1。请帮忙。

设置这个应该改变协议:

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

PS : 在 powershell v5

中检查

设置多个安全协议:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12;