Update: This is an older script that I had written for work, and it hasn’t been tested for a long time. The idea of the script was to use PowerShell to silently download and install Java 8 JRE. Since Oracle has change their licensing terms on using Java in business environments, I recommend using Adoptium Eclipse Temurin as an open-source alternative.
Back to the Script
This script I wrote for our automation system that will:
- Download the latest Java 8 JRE from Java.com
- Save in a local directory C:\Install
- Create a Install Options File
- Run the installer silently with the necessary Installer Options
The Installer Options file determines what configuration is used the install of Java.
For example, in the script I have configured. This will perform a silent install, auto updates enabled, no reboot after the installation, Sponsors/ads install disabled and will uninstall any older existing installations of Java JRE.
- INSTALL_SILENT=Enable
- AUTO_UPDATE=Enable
- REBOOT=Disable
- SPONSORS=Disable
- REMOVEOUTOFDATEJRES=Enable
You can find these and other options to use from the Java website:
This has been tested to work on PowerShell v2 and higher.
PowerShell Script
--------------------------------------------------------------------------
Deploy Java JRE Software
Date: 21-Sept-2016
Created by: Daniel Burrowes
--------------------------------------------------------------------------
Description:
Downloads the Java installer and installs silently
--------------------------------------------------------------------------
# -Verbose and -Debug
[CmdletBinding()]
param( )
# --------------------------------------------------------------------------
Write-Verbose "Setting Global Variables..."
$InstallDir = "c:InstallJava"
$Source = "http://javadl.oracle.com/webapps/download/AutoDL?BundleId=211996"
$Destination = "$InstallDirjava.exe"
$Options = "$InstallDirjava_options.txt"
#Create install directory
Write-Verbose "Creating Install Directory"
New-Item -Path $InstallDir -ItemType directory -Force
Write-Verbose "Downloading Software..."
$start_time = Get-Date
(New-Object System.Net.WebClient).DownloadFile($Source, $Destination)
Write-Verbose "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"
Write-Verbose "Creating Installer Options File..."
$text = 'INSTALL_SILENT=Enable
AUTO_UPDATE=Enable
REBOOT=Disable
SPONSORS=Disable
REMOVEOUTOFDATEJRES=Enable
'
# Create file
$text | Set-Content $Options
#Running the installer
Write-Verbose "Executing Java Install.."
Start-Process -FilePath $Destination -ArgumentList "INSTALLCFG=$Options /s /L $InstallDirjre-install.log" -Wait -Verbose -PassThru
Check out my other PowerShell related articles here!