Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
$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
}
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:
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()
This topic is 4 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.