top of page

PowerShell Script for Silent Java 9 Installer

  • Mohan Sekar
  • Nov 15, 2017
  • 1 min read

Java 9 Silent Installer PowerShell Script

function Install-Java { $OS = (gwmi win32_operatingsystem).osarchitecture if ($OS -ne '64-bit') { Write-Host "OS Architecture is not equal to 64-bit. Please use $OS JDK file for installation." Exit } $JDK_FULL_VER="9+181" $JDK_VER="9" $JDK_PATH="-9" $source64 = "http://download.oracle.com/otn-pub/java/jdk/$JDK_FULL_VER/jdk-$JDK_VER"+"_windows-x64_bin.exe" $destination64 = ($env:TEMP + "\$JDK_VER-x64.exe") $client = new-object System.Net.WebClient $cookie = "oraclelicense=accept-securebackup-cookie" $client.Headers.Add([System.Net.HttpRequestHeader]::Cookie, $cookie) Write-Host 'Checking if Java is already installed' if ((Test-Path "c:\Program Files (x86)\Java") -Or (Test-Path "c:\Program Files\Java")) { Write-Host 'No need to Install Java' Exit } Write-Host "Downloading x64 to $destination64" $client.downloadFile($source64, $destination64) if (!(Test-Path $destination64)) { Write-Host "Downloading $destination64 failed" Exit } try { Write-Host 'Installing JDK-x64' $proc1 = Start-Process -FilePath "$destination64" -ArgumentList "/s REBOOT=ReallySuppress" -Wait -PassThru $proc1.waitForExit() Write-Host 'Installation Done.' } catch [exception] { write-host '$_ is' $_ write-host '$_.GetType().FullName is' $_.GetType().FullName write-host '$_.Exception is' $_.Exception write-host '$_.Exception.GetType().FullName is' $_.Exception.GetType().FullName write-host '$_.Exception.Message is' $_.Exception.Message } if ((Test-Path "c:\Program Files (x86)\Java") -Or (Test-Path "c:\Program Files\Java")) { Write-Host 'Java installed successfully.' } Write-Host 'Setting up Path variables.' if (Test-Path "c:\Program Files (x86)\Java") { [System.Environment]::SetEnvironmentVariable("JAVA_HOME", "c:\Program Files (x86)\Java\jdk$JDK_PATH", "Machine") [System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";c:\Program Files (x86)\Java\jdk$JDK_PATH\bin", "Machine") } else { [System.Environment]::SetEnvironmentVariable("JAVA_HOME", "c:\Program Files\Java\jdk$JDK_PATH", "Machine") [System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";c:\Program Files\Java\jdk$JDK_PATH\bin", "Machine") } Write-Host 'Done.Goodbye!!' } Install-Java

Comments


RECENT POSTS:
SEARCH BY TAGS:

© 2023 by NOMAD ON THE ROAD. Proudly created with Wix.com

  • b-facebook
  • Twitter Round
  • Instagram Black Round
bottom of page