Invoke-WebRequest Windows PowerShell 5.1 is scaring me…

So I just ran into this:

PS C:Userszeroadmin> $WindowsNativeLinuxUtilsZipUrl = "" PS C:Userszeroadmin> Invoke-WebRequest -Uri $WindowsNativeLinuxUtilsZipUrl -OutFile "$" Invoke-WebRequest : The request was aborted: Could not create SSL/TLS secure channel. At line:1 char:1 + Invoke-WebRequest -Uri $WindowsNativeLinuxUtilsZipUrl -OutFile "$HOME ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand 

…and I solved it by adding this line right before I use Invoke-WebRequest

# Solution from: [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" 

…but…is this something I have to worry about now everytime I use Invoke-WebRequest with an https site? Is there a better more consistent way so I don’t need this extra line beforehand just in case a site might require TLS 1.2?

Thank god PowerShell Core doesn’t have this problem (I assume because /u/markekraus is a badass…Maybe he’ll drop us a comment and tell us why this is not a problem in PowerShell Core?)

submitted by /u/fourierswager
[link] [comments]

Leave a Reply