Search code examples
javapowershellazureazure-automation

Java Server JRE Not Registering via Remote PowerShell Install. Works with PowerShell ISE


I developed a PowerShell script that installs Java Server JRE and registers the environmental variables. It works when I run it via PowerShell ISE but fails if I try to execute the PowerShell remotely. I remotely execute by attaching the script as a CSE to the desired VM via Azure Automation.

The weird part is that the remote PowerShell install shows the Environment Variables. If I open the Environment Variables GUI edit/save it then edit and save it back to the correct path it starts working (ex. edit and add a \bin and save, edit and remove \bin and save). Via local PowerShell ISE execution of my script, I don't have to do this, it just works. Am I missing some sort of registration step to get the Java Server JRE.

$solrPath = "C:\Solr"
# Get Zip file containing Java Server JRE from CDN
Invoke-WebRequest -Uri 'http://mycdn.com/Solr/Downloads/jdk1.8.0_144.zip' -OutFile C:\mydir\java.zip
Write-Output "Java Server JRE Zip file downloaded from CDN"

# Unzip Java Server JRE Directory
Expand-Archive -Path C:\mydir\java.zip -DestinationPath $solrPath -Force
Write-Output "Java Server JRE Zip file extracted"

# Set Java Path and Home Environmental Variables
# Add the PATH environment variable to point to the Java Directory Bin
$oldpath = (Get-ItemProperty -Path ‘Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment’ -Name PATH).path
$newpath = “$oldpath;$solrPath\jdk1.8.0_144\jre\bin” 
Set-ItemProperty -Path ‘Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment’ -Name PATH –Value $newpath
$donepath = (Get-ItemProperty -Path ‘Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment’ -Name PATH).path
Write-host "Validation; new value set to $donepath"

Solution

  • It ended up being an issue with another part of my script. Once I corrected that, Java installed correctly.