I'm trying to add %JAVA_HOME%\bin to Path environment variables via Powershell script.
The JAVA_HOME variable itself is pointing to C:\Program Files\Java\jdk1.8.0_172.
When I added %JAVA_HOME%\bin manually from the Environment Variable window
Then call this line of code from Powershell to get value of Path variable
[Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine) It seems like the result from executing line above converts %JAVA_HOME%\bin to the actual path that I've defined which is C:\Program Files\Java\jdk1.8.0_172.
The output look like this
...;C:\Program Files\nodejs;C:\Program Files\Java\jdk1.8.0_172\bin; But when I added %JAVA_HOME%\bin via Powershell script with the code below
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine) + "%JAVA_HOME%\bin", [EnvironmentVariableTarget]::Machine) Then run GetEnvironmentVariable function again, the output is different than when I added the path through the environment variable window. It doesn't convert %JAVA_HOME%\bin to the actual path.
The output looks like this
....;C:\Program Files\nodejs\;C:\Program Files\Java\jdk1.8.0_172\bin;%JAVA_HOME%\bin Is this expected? Or is there something that I am missing?
I can actually just append the real path to Path variable directly, but I want to make use of JAVA_HOME variable so the path will be in 1 location.
