If you follow my blog you’ve probably seen the trend of my install scripts being transformed into evergreen scripts crawling vendors website for executables.
You see, at every new version of my Automation Framework I manually updated all download links in tons of install wrappers. This is very time consuming and not to mention that they’re outdated in just a couple of weeks.
So as I convert these I blog and put them up on my Github repo which is the base of my free Automation Framework Community Edition.
Today I’m very pleased to share an evergreen install script for Oracle Java SE Runtime Environment.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# https://www.reddit.com/r/PowerShell/comments/4fgbv4/powershell_function_to_get_latest_java_release/ # All Credits to gangstanthony # PowerShell Wrapper for MDT, Standalone and Chocolatey Installation - (C)2015 xenappblog.com # Example 1: Start-Process "XenDesktopServerSetup.exe" -ArgumentList $unattendedArgs -Wait -Passthru # Example 2 Powershell: Start-Process powershell.exe -ExecutionPolicy bypass -file $Destination # Example 3 EXE (Always use ' '): # $UnattendedArgs='/qn' # (Start-Process "$PackageName.$InstallerType" $UnattendedArgs -Wait -Passthru).ExitCode # Example 4 MSI (Always use " "): # $UnattendedArgs = "/i $PackageName.$InstallerType ALLUSERS=1 /qn /liewa $LogApp" # (Start-Process msiexec.exe -ArgumentList $UnattendedArgs -Wait -Passthru).ExitCode Write-Verbose "Setting Arguments" -Verbose $StartDTM = (Get-Date) $Vendor = "Oracle" $Product = "Java SE Runtime Environment" $PackageName = "JRE_x64" $Page = Invoke-WebRequest http://java.com/en/download/windows_offline.jsp $Version = $page.RawContent -split "`n" | ? {$_ -match 'recommend'} | select -f 1 | % {$_ -replace '^[^v]+| \(.*$'} $InstallerType = "exe" $Source = "$PackageName" + "." + "$InstallerType" $LogPS = "${env:SystemRoot}" + "\Temp\$Vendor $Product $Version PS Wrapper.log" $LogApp = "${env:SystemRoot}" + "\Temp\$PackageName.log" $Destination = "${env:ChocoRepository}" + "\$Vendor\$Product\$Version\$packageName.$installerType" $url = $page.links.href | ? {$_ -match '^http.*download'} | select -f 1 $ProgressPreference = 'SilentlyContinue' $UnattendedArgs = '/s REBOOT=0 SPONSORS=0 AUTO_UPDATE=0' Start-Transcript $LogPS if( -Not (Test-Path -Path $Version ) ) { New-Item -ItemType directory -Path $Version } CD $Version Write-Verbose "Downloading $Vendor $Product $Version" -Verbose If (!(Test-Path -Path $Source)) { Invoke-WebRequest -Uri $url -OutFile $Source } Else { Write-Verbose "File exists. Skipping Download." -Verbose } Write-Verbose "Starting Installation of $Vendor $Product $Version" -Verbose (Start-Process "$PackageName.$InstallerType" $UnattendedArgs -Wait -Passthru).ExitCode Write-Verbose "Customization" -Verbose Write-Verbose "Stop logging" -Verbose $EndDTM = (Get-Date) Write-Verbose "Elapsed Time: $(($EndDTM-$StartDTM).TotalSeconds) Seconds" -Verbose Write-Verbose "Elapsed Time: $(($EndDTM-$StartDTM).TotalMinutes) Minutes" -Verbose Stop-Transcript |
Running this downloads and installs the latest version of java matching the bitness of the system. This seems to be due to the URL used in the $Page variable, as this site does a system check to recommend the version.
Did you consider using the site: https://www.java.com/en/download/manual.jsp to be able to pull both x64 and x86 installations? I know our usage demands that both versions be installed on clients. I’m working on tweaking the script to account for this, but wondering if you attempted and ran into any walls.
Thanks!
Hi Derek, I did not since I’m only using x64 & the fact that Java is dead.
Thank you for this, you’re saving me a lot of work. 🙂
Some of out here are still forced to deploy archaic and seemingly dead runtimes to support ERP systems and the like. This will be useful for TeamViewer and Print Drivers also.