Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

PowerShell Invoke-WebRequest The request was aborted Could not create SSL TLS secure channel

I was testing automating few banking websites to check uptime, Invoke-WebRequest is use to access webiste, using this command I wrote a script to access bank website with PowerShell commands, but while executing scripts it was failing to access web site and showing below error.

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

The cause of the error is Powershell by default uses TLS 1.0 to connect to website, but website security requires TLS 1.2. You can change this behavior with running any of the below command to use all protocols. You can also specify single protocol.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Tls12, [Net.SecurityProtocolType]::Ssl3
[Net.ServicePointManager]::SecurityProtocol = "Tls, Tls11, Tls12, Ssl3"

The HTTP status code 200 indicates that the request has succeeded.

Useful Articles
PowerShell Invoke-WebRequest The underlying connection was closed: Could not establish trust relationship for the Ssl Tls Secure channel.
Different ways to bypass Powershell execution policy :.ps1 cannot be loaded because running scripts is disabled
Powershell Trick : Execute or run any file as a script file
Set Powershell execution policy with Group Policy
Powershell execution policy setting is overridden by a policy defined at a more specific scope

This post first appeared on Tales From Real IT System Administrators World And Non-production Environment, please read the originial post: here

Share the post

PowerShell Invoke-WebRequest The request was aborted Could not create SSL TLS secure channel


Subscribe to Tales From Real It System Administrators World And Non-production Environment

Get updates delivered right to your inbox!

Thank you for your subscription