Menu

Enabling TLS1.2 in PowerShell and Getting Ready for Windows Terminal
🖼️
0

Enabling TLS1.2 in PowerShell and Getting Ready for Windows Terminal

Reading 0:00
15s threshold

The Problem: Sometimes PowerShell ISE returns the following TLS-triggered error when one implements Invoke-WebRequest or Invoke-RestMethod during a session: “The underlying connection was closed: An unexpected error occurred on a receive…” ( https://stackoverflow.com/questions/66050990/the-underlying-connection-was-closed-an-unexpected-error-occurred-on-a-receive ). The Solution: To avoid said error, enable TLS (Transport Layer Security, https://docs.microsoft.com/en-us/microsoft-365/compliance/prepare-tls-1.2-in-office-365?view=o365-worldwide ) by adding the following line before using Invoke-WebRequest (or Invoke-RestMethod): [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 For instance, to retrive URIs from mit.edu, use [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 (Invoke-WebRequest -Uri ‘mit.edu’).links.href Similarly, to retrieve URIs from Google search results for the [corona virus] query, use [Net.ServicePointManager]::SecurityProtocol…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More