Browser limitation detected

Facebook browser may limit features like the Menu. For the best experience, please tap (...) and choose 'Open in Browser'.

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

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

— 1 min read

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

data-mapping="pathname" data-strict="0" data-reactions-enabled="0" data-emit-metadata="0" data-input-position="top" data-theme="preferred_color_scheme" data-lang="en" data-loading="lazy" crossorigin="anonymous" async>
banner-Bastien Perez
Bastien Perez avatar

Freelance Microsoft 365 - Active Directory - Modern Workplace

France