Skip to content

Instantly share code, notes, and snippets.

@JurrianFahner
Created May 1, 2021 09:52
Show Gist options
  • Save JurrianFahner/ed6d0a30c9ae7cbaf3dad93e5fe2e6ec to your computer and use it in GitHub Desktop.
Save JurrianFahner/ed6d0a30c9ae7cbaf3dad93e5fe2e6ec to your computer and use it in GitHub Desktop.
Java switch script for powerhsell
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