Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

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 https://bank.com
Invoke-WebRequest : The request was aborted: Could not create SSL/TLS secure channel.
At line:1 char:1
+ Invoke-WebRequest -Uri https://www.icicibank.com
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Powershell Invoke-WebRequest -uri The request was aborted could not create ssl tls secure channel system.nethttpwebrequest webexception fullyqualifiederrorid webcmdletwebresponseexception.png

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.

Microsoft Powershell invoke-Webrequest -uri [net.servicemanager] security protocol [net.securityprotocoltype] tls ssl tls12 secure error allow tls12.png

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
POWERSHELL FUN SEND KEYS ON THE SCREEN

Go Back

Comment

Blog Search

Page Views

3770732

Follow me on Blogarama