Invoke-WebRequest Windows PowerShell 5.1 is scaring me…

So I just ran into this:

PS C:Userszeroadmin> $WindowsNativeLinuxUtilsZipUrl = "https://github.com/pldmgg/WindowsNativeLinuxUtils/raw/master/MSYS2_20161025/bsdtar.zip" PS C:Userszeroadmin> Invoke-WebRequest -Uri $WindowsNativeLinuxUtilsZipUrl -OutFile "$HOMEDownloadsbsdtar.zip" 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: https://stackoverflow.com/questions/41618766/powershell-invoke-webrequest-fails-with-ssl-tls-secure-channel [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