May 6, 2016

executing a command in powershell, where the path comes from an environment variable

The environment can be accessed in the powershell with the $env command:

PS C:\dev\Tools> $env:JAVA_HOME

To execute a java with the JAVA_HOME you use "&" to start an external command in the 

PS C:\dev\Tools> &$($env:JAVA_HOME + "\bin\java") -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 7.1.012)
SAP Java Server VM (build 7.1.012 23.5-b11, Aug  8 2013 23:45:34 - 71_REL - optU - windows amd64 - 6 - bas2:201691 (mixed mode))