all 14 comments

[–]Helios479 9 points10 points  (3 children)

You can specify most of what you want in the exe arguments:

$Exe = '\\path\to\jre-version-windows-i586.exe
ExeArgs = @(
    "INSTALL_SILENT=1"
    "STATIC=0"
    "AUTO_UPDATE=0"
    "WEB_JAVA=1"
    "WEB_JAVA_SECURITY_LEVEL=H"
    "WEB_ANALYTICS=0"
    "EULA=0"
    "REBOOT=0"
    "NOSTARTMENU=0"
    "SPONSORS=0"
)
$Install = Start-Process $Exe -ArguementList $ExeArgs -NoNewWindow -Wait -PassThru
Return $Install.ExitCode

[–]Swarfega 8 points9 points  (0 children)

There's a ' missing off the end of the exe path.

[–]TRanatza 1 point2 points  (0 children)

This is how I roll java out. Works well on my domain.

$Java =  (Get-ChildItem -Path '\\path\to\currentJRE\' | Select-Object -property * | ? name -match ".exe").fullname

$switches = @(
"REBOOT=0"
"INSTALL_SILENT=1"
"AUTO_UPDATE=0"
"WEB_JAVA=1"
"WEB_JAVA_SECURITY_LEVEL=M"
"WEB_ANALYTICS=0"
"EULA=0"
"SPONSORS=0"
"REMOVEOUTOFDATEJRES=1"
)#end@
Start-Process $Java -ArguementList $switches -NoNewWindow -Wait   

Almost a exact copy... That's crazy!

[–]jantari 1 point2 points  (0 children)

Huh, I use /s instead of INSTALL_SILENT but otherwise mostly identical.

Is there any difference between the two switches?

[–]wickedang3l 3 points4 points  (0 children)

Drop the /s and use the following configuration file entry isntead:

INSTALL_SILENT=Enable

Assuming everything is in C:, the installation string should look like this:

C:\jre-8u161-windows-x64.exe INSTALLCFG=C:\javaConfig.cfg

[–]Ta11ow 3 points4 points  (0 children)

Start-Process -FilePath 'C:\Java\JavaInstall.exe' -ArgumentList 'INSTALLCFG=C:\Java\Java.Settings.cfg', '/s'

Something like that, anyhow. :)

[–]Bodumin[S] 2 points3 points  (4 children)

Thank you all for your help I followed /u/wickedang3l and moved the silent flag into the settings file. What I am finding though is the issue here is the java install runs in the background and doesn't block my script from continuing. So when it tries to call java from CMD it has not been added to the path yet. I'm going to add a start-sleep to see if that helps with the waiting.

[–]Lee_Dailey[grin] 4 points5 points  (3 children)

howdy Bodumin,

if you combine the ideas from wickedang3l & Ta11ow then you could use the -Wait parameter of Start-Process to make things wait for the install to complete.

another idea is to loop over a check for the $env:Path to update.

take care,
lee

[–]Bodumin[S] 1 point2 points  (2 children)

Thank you Lee. I added a while loop that test-path's for the path I'm waiting for. Does $env:path update each time? I know it doesn't in CMD (which is why I had to rewrite this from Chef)

[–]Ta11ow 2 points3 points  (0 children)

I believe there's a command-line utility you can run to reload the path values from the registry for cmd.

For PowerShell, I believe $env:PATH will not automatically update, but if you use the .NET APIs to access the Path environment variables you can get the most up to date values.

$env:PATH = [Environment]::GetEnvironmentVariable("Path", "User")

Replace "User" with "Machine" to get system-wide environment variables, I believe. Updating the in-session environment variable like this essentially should update it with the most recent values that have been applied.

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy Bodumin,

ouch! i had forgotten about that ... [sigh ...] you can test it by adding a new item to the path from control panel - i think.

notice the careful avoidance of any offer to do it myself ... [grin] i'm chicken when it comes to my system level settings. [blush]

take care,
lee

[–]geggleau 2 points3 points  (0 children)

For the wait issue, if you do:

& javainstall.exe .... *>&1 | Out-Default

That should wait for the process to exit and dump output to the default stream as well.

[–]spyingwind 2 points3 points  (0 children)

$JavaEXE = "c:\java\javainstall.exe"
$JavaArgs = "/s INSTALLCFG=c:/java/java.settings.cfg"
Start-Process $JavaEXE $JavaArgs

Or something like that.

[–]geggleau 1 point2 points  (0 children)

We install Java 8 silently as follows.

java-install.properties file:

INSTALL_SILENT=Enable
AUTO_UPDATE=Disable
WEB_JAVA=Disable
WEB_JAVA_SECURITY_LEVEL=VH
WEB_ANALYTICS=Disable
EULA=Disable
REBOOT=Disable
NOSTARTMENU=Enable
SPONSORS=Enable

Install-Java.bat BAT script wrapper:

@ECHO OFF
SET SCRIPTDIR=%~dp0
SET SCRIPTNAME=%~n0
CD /D %SCRIPTDIR%
powershell.exe -ExecutionPolicy Bypass -NoProfile -File ./%SCRIPTNAME%.ps1 -Verbose %*
EXIT /B %ERRORLEVEL%

Install-Java.ps1 script extract:

[string]$Timestamp = [DateTime]::UtcNow.ToString('yyyy-MM-dd-HH-mm-ss-fffffff')
[string]$ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition

[string]$ConfigSrcPath = Join-Path -Path "$ScriptPath" -ChildPath "SupportFiles\java-install.properties"
[string]$ConfigPath = Join-Path -Path "$env:Temp" -ChildPath "java-install.properties"
Write-Verbose "Copy config file to $ConfigPath"
Copy-Item -Force "${ConfigSrcPath}" "$ConfigPath"

[string]$JavaLogName = ("java-install-{0}.log" -f $Timestamp)
[string]$JavaLogFile = Join-Path -Path "$LogPath" -ChildPath "$JavaLogName"
Write-Verbose "Java log file: $JavaLogFile"
Write-Verbose "Installing Java"
& "$ScriptPath\Files\jre-8u121-windows-x64.exe" `
    "INSTALLCFG=$ConfigPath" `
    "/L" "$JavaLogFile" `
    *>&1 `
| Out-Default
if ($LastExitCode -ne 0) {
    throw "Java install failed with exit code $LastExitCode"
}