Download file using Powershell script no working anymore due to URL change?
Posted: Wed Jul 03, 2019 9:01 pm
Hi,
Can anyone here please assist me what's wrong with the lines of code below?
It used to be working and save the files in the directory as Jave RE engine offline components.
I got the below error message instead:
Can anyone here please assist me what's wrong with the lines of code below?
Code: Select all
$Time = Get-Date -format 'F'
$DownloadDirectory = "C:\TEMP\JAVA"
$DownloadedFiles = Get-ChildItem -Path "$DownloadDirectory\*jre*.exe" -Force | Where-Object {!$_.PSIsContainer}
$DownloadedFiles | Remove-Item -Force
Try {
$Link = (Invoke-WebRequest -UseBasicParsing –Uri 'https://www.java.com/en/download/manual.jsp').Links | Where-Object { $_.href -like "http*" } | Where-Object { $_.title -like "Download Java software for Windows (64-bit)" }
Invoke-WebRequest $Link[0].href -OutFile "$($DownloadDirectory)\jre64x.exe"
$Link = (Invoke-WebRequest -UseBasicParsing –Uri 'https://www.java.com/en/download/manual.jsp').Links | Where-Object { $_.href -like "http*" } | Where-Object { $_.title -like "Download Java software for Windows Offline" }
Invoke-WebRequest $Link[0].href -OutFile "$($DownloadDirectory)\jre32x.exe"
}
Catch [Exception] {
$ErrorMessage = $_.Exception
Send-MailMessage -From "$env:COMPUTERNAME@$env:userdnsdomain" -To 'IT@domain.com' -Subject "Java Runtime Download Failed! - $($Error[0]) - as at $($Time)" -SmtpServer mail.domain.com -Body "The error message was $($ErrorMessage)"
Break
}
Finally {
Write-Host "Both Java Runtime $($DownloadedFiles) has been downloaded succesfully as at $($Time) and saved into $($DownloadDirectory)" -ForegroundColor Yellow
}
I got the below error message instead:
Thanks in advance.The error message was System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()