Powershell将安全协议设置为Tls 1.2

时间:2017-01-16 10:43:15

标签: powershell webclient

我正在使用此代码

        $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。请帮忙。

1 个答案:

答案 0 :(得分:12)

设置此项应更改协议:

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

PS:签入powershell v5

设置多个安全协议:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12;
相关问题