Actually, I did find out a way to download and install JRE with PowerShell script.It is really use-full therefore I wanted to share it here in StackExchange. This script can be optimized but it does the job as it is.
Below is the entire script:
https://github.com/erjan123/Sitecore/blob/master/Sitecore/PowershellScripts/Sitecore%20Solr/2.install-solr-7.5-and-JRE.ps1
I have also a tutorial that explains the script:
https://www.youtube.com/watch?v=3-27syl8C98&t=10s
$downloadInstallJRE = $true,
$JREVersion64 = $true
if($downloadInstallJRE -eq $true)
{
if($JREVersion64 -eq $true)
{
$URL=(Invoke-WebRequest -UseBasicParsing https://www.java.com/en/download/manual.jsp).Content | ForEach-Object{[regex]::matches($_, '(?:<a title="Download Java software for Windows \(64-bit\)" href=")(.*)(?:">)').Groups[1].Value}
}
else
{
$URL=(Invoke-WebRequest -UseBasicParsing https://www.java.com/en/download/manual.jsp).Content | ForEach-Object{[regex]::matches($_, '(?:<a title="Download Java software for Windows Online" href=")(.*)(?:">)').Groups[1].Value}
}
Invoke-WebRequest -UseBasicParsing -OutFile jre8.exe $URL
Start-Process .\jre8.exe '/s REBOOT=0 SPONSORS=0 AUTO_UPDATE=0' -wait
if($JREVersion64 -eq $true)
{
$JREVersion = Get-ChildItem -Path "C:\Program Files\Java" -name | Where-Object { -not $_.PsIsContainer } | Sort-Object LastWriteTime -Descending | Select-Object -first 1
Write-Host "JREVersion: $JREVersion"
$JREPath = "C:\Program Files\Java\$JREVersion"
Write-Host "JREPath" + $JREPath
Write-Host "Downloading 64 bit of JRE"
}
else{
$JREVersion = Get-ChildItem -Path "C:\Program Files (x86)\Java" -name | Where-Object { -not $_.PsIsContainer } | Sort-Object LastWriteTime -Descending | Select-Object -first 1
Write-Host "JREVersion: $JREVersion"
$JREPath = "C:\Program Files (x86)\Java\$JREVersion"
Write-Host "JREPath " + $JREPath
Write-Host "Downloading 32 bit of JRE"
}
Write-Host "JRE package URL " $URL
}