Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell Setting Security Protocol to Tls 1.2 [duplicate]

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.

like image 963
Harsha Avatar asked Jan 16 '17 10:01

Harsha


People also ask

How do you check if TLS 1.2 is enabled using PowerShell?

How to check if TLS 1.2 is enabled? If the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client\DisabledByDefault is present, the value should be 0.

What TLS version is PowerShell using?

Check-or-Enable-TLS-1.2-with-PowerShell As of April 2020, the PowerShell Gallery only supports connections using TLS 1.2 or later. For more information, see PowerShell Gallery TLS Support.


1 Answers

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;
like image 85
ClumsyPuffin Avatar answered Oct 18 '22 10:10

ClumsyPuffin