Set environment variable from PowerShell:
[environment]::SetEnvironmentVariable(“<variable name>”,“variable value”,“Machine”)
Ex: [environment]::SetEnvironmentVariable(“JAVA_HOME”,“C:\Program Files (x86)\Java”,“Machine”)
This example sets a system wide variable. Replacing “Machine” with “User” will set a variable for the current user.