Created
May 1, 2021 09:52
-
-
Save JurrianFahner/ed6d0a30c9ae7cbaf3dad93e5fe2e6ec to your computer and use it in GitHub Desktop.
Java switch script for powerhsell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param($java_version) | |
$java_install_dir = switch($java_version) | |
{ | |
8 {"C:\Program Files\Zulu\zulu-8"} | |
15 {"C:\Program Files\Zulu\zulu-15"} | |
default {"unknown"} | |
} | |
if ($java_install_dir -ne "unknown") { | |
$old_path=(Get-ChildItem env:Path).value | |
Set-Item -Path Env:JAVA_HOME -Value "$java_install_dir" | |
Set-Item -Path Env:Path -Value "$java_install_dir/bin;$old_path" | |
java -version | |
} else { | |
write-host "please give in java version number" | |
write-host "example: switch-java 8" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment