Files

100 lines
3.6 KiB
PowerShell
Raw Permalink Normal View History

2025-08-09 04:19:02 +00:00
<#
Author: Gabe Kerntke
Date: 02-22-2024
.Synopsis
.Modified
2024-02-22 (GabeK) - Original script created
2025-08-06 (GabeK) - Updated to use functions script
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $false)]
$App_Name = "Java 8 Update",
[Parameter(Mandatory = $false)]
$File_Name_Extension = "exe",
[Parameter(Mandatory = $false)]
$Install_Parameters = "/s REMOVEOLDERJRES=1",
[Parameter(Mandatory = $false)]
$EPCache_Folder = "3rd Party Patches\$App_Name",
[Parameter(Mandatory = $false)]
$File_Name = "$File_Name_Prefix-$Online_Version.$File_Name_Extension"
)
Function Get-Java_URL {
$mapXML = Invoke-RestMethod "https://javadl-esd-secure.oracle.com/update/1.8.0/map-1.8.0.xml" -UserAgent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36 Edg/90.0.818.46'
#Select latest build from entries marked as 'critical'
$target = ($mapXML.'java-update-map'.mapping | Where-Object { $_.critical -eq 1 } | Select-Object -Last 1)
$params = @{
'Uri' = [string]$target.url
'ContentType' = 'application/xml'
'UserAgent' = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36 Edg/90.0.818.46'
}
$javaXml = Invoke-RestMethod @params
#substituting the 'au' (automatic update) value in the url with the desired architecture.
$javaUpdateInfo = $javaXml.'java-update'.information
$DownloadURL = [string]($javaUpdateInfo.url) -replace '\-au', "$Java_Version"
Return $DownloadURL
}
Function Install-Java_64bit {
$File_Name_Prefix = "jre-x64"
$Java_Version = "-x64"
$DownloadURL = Get-Java_URL
$A = $DownloadURL.substring(115)
$Online_Version = $A.Substring(0, $A.Length - 26) -replace ("-", "") -replace ("U", ".")
. "C:\Temp\Script Cache\Functions.ps1"
Test-Probe_Online
Install-App
}
Function Install-Java_32bit {
$File_Name_Prefix = "jre-x32"
$Java_Version = "-i586"
$DownloadURL = Get-Java_URL
$A = $DownloadURL.substring(115)
$Online_Version = $A.Substring(0, $A.Length - 26) -replace ("-", "") -replace ("U", ".")
. "C:\Temp\Script Cache\Functions.ps1"
Test-Probe_Online
Install-App
}
#Region Script Start
If ((Test-Path "C:\Temp\Script Cache") -eq $False) { New-Item -ItemType directory -Path "C:\Temp\Script Cache" }
Invoke-WebRequest -UseBasicParsing "https://scripts.gabesville.com/Gabesville/Powershell-Scripts/raw/branch/main/Functions%20Scripts/Functions.ps1" -outfile "C:\Temp\Script Cache\Functions.ps1"
. "C:\Temp\Script Cache\Functions.ps1"
#Check to see if program is installed
$Applist = Get-Software | Sort-Object -Descending
If ($Applist.DisplayName -like "$App_Name*") {
$List = Write-Output ($Applist.DisplayName -like "$App_Name*")
If ($List.Count -eq 2 -and $Applist.DisplayName -like "$App_Name*(64-bit)") {
Write-Host "Both 32bit and 64bit versions of Java are installed"
Close-App
Uninstall-App_WMIobject
Install-Java_64bit
Install-Java_32bit
Exit
}
If ($Applist.DisplayName -like "$App_Name*(64-bit)") {
Write-Host "64bit version of Java is installed"
Close-App
Uninstall-App_WMIobject
Install-Java_64bit
Exit
}
If ($Applist.DisplayName -like "$App_Name*") {
Write-Host "32bit version of Java is installed"
Close-App
Uninstall-App_WMIobject
Install-Java_32bit
}
}
Else { Write-Host "Java is not installed, exiting." }
#Region Script End