Skip to content

Instantly share code, notes, and snippets.

@JohnL4
Last active February 2, 2018 16:43
Show Gist options
  • Save JohnL4/4f819b1db6a1dc6e19ee0d3da18e9fba to your computer and use it in GitHub Desktop.
Save JohnL4/4f819b1db6a1dc6e19ee0d3da18e9fba to your computer and use it in GitHub Desktop.
Set string environment variable (e.g., $env:JAVA_HOME) to most-recently-created subdirectory
# So, we're not dependent on filename sort order ("9" > "10").
if (Test-Path "c:/usr/local/Java") {
$env:JAVA_HOME = $(ls c:/usr/local/Java | sort CreationTime -desc | select -first 1 FullName).FullName
}
else {
Write-Warning "No Java"
}
# TODO: could probably use a list of directories to search (e.g., @("c:/usr/local/Java", "c:/Program Files/Java")).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment