Photo by Joshua Sortino / Unsplash
Invoke-WebRequest and Invoke-RestMethod failed with SSL/TLS

Invoke-WebRequest and Invoke-RestMethod failed with SSL/TLS

Published on 27 Sep 2019

Bastien Perez
Bastien Perez

Clap

When running the Invoke-WebRequestor Invoke-RestMethod command, you may encounter this error:

The request was aborted: Could not create SSL/TLS secure channel.
At line:1 char:1
+ Invoke-WebRequest https://xxxxx
>+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

By default PowerShell uses TLS 1.0 and the remote ressource is configured ito use TLS 1.2. To tell PowerShell to use TLS 1.2, you need to run:

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

Note: Only the current PowerShell session (PowerShell window) will be in TLS 1.2, you must therefore execute this command each time you open the PowerShell window or put it in your PowerShell profile.

Comments

banner-Bastien Perez
Bastien Perez

Freelance Microsoft 365 - Active Directory - Modern Workplace

France