1

I have this simple script that works on a laptop:

[Net.ServicePointManager]::SecurityProtocol
[enum]::GetNames([Net.SecurityProtocolType])

$url = "https://www.contextures.com/SampleData.zip"

wget -Uri $url -OutFile "C:\temp\temp.zip"

But when I'm trying to run it on a server I'm always getting this error:

wget : The request was aborted: Could not create SSL/TLS secure channel.

Any ideas what might be causing this? Any help would be appreciated.

I already tried this and still getting the same error message:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
hod
  • 750
  • 7
  • 21
  • https://stackoverflow.com/questions/41618766/powershell-invoke-webrequest-fails-with-ssl-tls-secure-channel *PowerShell by default uses TLS 1.0 while most sites require TLS 1.2* – SP Tutors Oct 01 '20 at 16:23
  • 1
    Does this answer your question? [Powershell Invoke-WebRequest Fails with SSL/TLS Secure Channel](https://stackoverflow.com/questions/41618766/powershell-invoke-webrequest-fails-with-ssl-tls-secure-channel) – SP Tutors Oct 01 '20 at 16:23
  • @SPTutors It results with the same error message – hod Oct 01 '20 at 16:28
  • @hod Are you sure you're using `Invoke-WebRequest` and not `wget.exe` by accident? – Tomalak Oct 01 '20 at 16:34
  • @Tomalak Yes I am. I tried `Invoke-WebRequest` and `wget`, same result. – hod Oct 01 '20 at 16:35
  • I can download the file no problem using `Invoke-WebRequest https://www.exaa.at/download/history/DSHistory2020.xls -OutFile DSHistory2020.xls`, without setting the `[Net.ServicePointManager]::SecurityProtocol` beforehand. Could it be that there are some components (such as virus scanners or proxies) messing with your SSL connection? – Tomalak Oct 01 '20 at 16:39
  • @Tomalak Yes, I can do the same on my laptop, but can't figure what might be preventing me from downloading this on a server. Does Invoke-WebRequest have some properties/methods to check what might be causing this? – hod Oct 01 '20 at 16:42
  • Your server might not have the necessary CA certificates in the root certificate list to allow the connection. Can you download the file in Internet Explorer on the server? – Tomalak Oct 01 '20 at 16:46
  • I tried accessing it using IE, and am getting message that the "Proxy server isn't responding" – hod Oct 01 '20 at 16:56
  • Are you actually using a Proxy server? If not, in IE, go `Tools -> Internet Options -> Connections -> LAN Settings` and uncheck the "Proxy server" checkbox. – Theo Oct 03 '20 at 11:31

2 Answers2

1

Set it to TLS 1.2:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Wasif
  • 14,755
  • 3
  • 14
  • 34
0

You can give a try with this example while adding $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12';


cls
$Folder = "$Env:Temp\DownloadFolder\"
# We create a SubFolder Named "DownloadFolder" in the temporary file %Temp% if it doesn't exists yet !
If ((Test-Path -Path $Folder) -eq 0) { New-Item -Path $Folder -ItemType Directory | Out-Null }

$urls=@('https://www.contextures.com/SampleData.zip',
'https://cdn2.unrealengine.com/Fortnite%2FBoogieDown_GIF-1f2be97208316867da7d3cf5217c2486da3c2fe6.gif'
)

$start_time = Get-Date
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12';
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols;

$i = 0
foreach($url in $urls)
{
    $i = $i + 1
    $output = $Folder + $url.Split("/")[-1]

Try {
        Write-Host "$i - Downloading" $output.Split("\")[-1] from $url
        (New-Object System.Net.WebClient).DownloadFile($url,$output)
    }

Catch

    {
        Write-Host "Error in : " $url -ForegroundColor Red -BackgroundColor Yellow
        Write-Host "Message: [$($_.Exception.Message)"] -ForegroundColor Red -BackgroundColor Yellow
        $i = $i - 1
    }
}

Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s) to download $i files"
ii $Folder
Hackoo
  • 18,337
  • 3
  • 40
  • 70