9

I am using this code

        $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)

This works well. What I want to do is that set the Security Protocol to Tls1.2 or Tls1.1. Please help.

Harsha
  • 129
  • 1
  • 1
  • 13

1 Answers1

40

setting this should change the protocol :

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

PS : checked in powershell v5

Setting Multiple Security Protocols:

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12;
wp78de
  • 18,207
  • 7
  • 43
  • 71
ClumsyPuffin
  • 3,909
  • 1
  • 17
  • 17
  • 2
    how to set that to use either Tls11 or Tls12? – Harsha Jan 17 '17 at 02:53
  • 3
    $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12' [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols https://stackoverflow.com/questions/36265534/invoke-webrequest-ssl-fails – Dragos Durlut Jul 13 '18 at 13:02
  • Where can I find out what brackets [] mean? – Shayan Jul 10 '22 at 17:29