PowerShell Invoke-WebRequest with TLS 1.2

The PowerShell function Invoke-WebRequest can be used to specifically invoke TLS 1.2 when writing a PowerShell script for example checking that a site is up for example or getting a response from an API.

The PowerShell function Invoke-WebRequest can be used to specifically invoke TLS 1.2 when writing a PowerShell script for example checking that a site is up for example or getting a response from an API.

Some webservers require a specific version is TLS is used for communication which may not match the default in your script execution. Then it is necessary to set the version TLS version in the script using ‘Net.SecurityProtocolType’ . The example below set the version of TLS to 1.2 before the Invoke-WebRequest function is executed.

Enable TLS 1.2 example

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest https://google.com/ -Method GET 

Enable TLS 1.1 example

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls11
Invoke-WebRequest https://google.com/ -Method GET 


I have also created a YouTube video of the InvokeWebRrequest function being used.

Leave a Reply

Your email address will not be published. Required fields are marked *