I would like to automate the installation of Adoptium. So far, I have been able to download the latest version of the .msi
$baseURL = "https://api.adoptium.net/v3/assets/feature_releases/11/ga" # Adoptium binaries and links
# Get versions and then [0] of the array that is returned to get the latest version
$response = Invoke-RestMethod -Uri $baseURL
$latestVersion = ($response.version_data.openjdk_version)[0]
# Locate the Windows MSI Installer
$downloadURL = ""
foreach ($asset in $response.binaries) {
if ($asset.architecture -eq "x64" -and $asset.image_type -eq "jre" -and $asset.os -eq "windows") {
$downloadURL = $asset.installer.link
$downloadPath = "$env:TEMP\$($asset.installer.name)" # Contains just the msi file name
break
}
}
# Download and run the installer
$global:progressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $downloadURL -OutFile $downloadPath
& $downloadPath
After this, I want to automate the installation, but have not been able to get this to work. I have got to this so far, but it doesn't work. My goal is to auto-select the four available options in the JRE installer:
- Add to PATH (selected by default)
- Associate .jar (selected by default)
- Set JAVA_HOME variable (not selected by default)
- JavaSoft (Oracle) registry keys (not selected by default)
How can I use the Adoptium JRE 11 installer to auto-install it with all four of these options?
# Define the path to the MSI installer
$installerPath = "$env:TEMP\OpenJDK11U-jre_x64_windows_hotspot_11.0.23_9.msi"
# Define the arguments for msiexec
$msiArgs = @(
"/i", "$installerPath", # Specify the path to the MSI installer
"/qn", # Quiet mode (no UI)
"/norestart", # Do not restart after installation
"INSTALLDIR=`"C:\Program Files\Java\jdk-11`"", # Specify the installation directory (change as needed)
"ADDLOCAL=FeatureMain,FeatureEnvironment,FeatureJarFileRunWith,FeatureJNLPFileRunWith,FeatureJavaHome", # Specify features to install
"SETUP_AUTO_UPDATE=0", # Disable automatic updates
"INSTALL_SILENT=Enable", # Enable silent installation
"ASSOCIATE_JNLP=Enable", # Associate .jnlp files
"ASSOCIATE_JAR=Enable", # Associate .jar files
"ASSOCIATE_JAD=Enable", # Associate .jad files
"INSTALLDIR_CONFESS=Enable" # Set installation directory
)
# Run msiexec with the defined arguments
Start-Process "msiexec.exe" -ArgumentList $msiArgs -Wait