Link to home
Start Free TrialLog in
Avatar of Systemadministration
Systemadministration

asked on

Setting new Syste, Variables using PowerShell Skript

Hello there,

I`m trying to set some own system-wide Windows environment-variables on Windows 7 machines using a Powershell-Skript:

The skript looks as following:

[Environment]::SetEnvironmentVariable("JAVA_HOME", "D:\Entwicklung\Programme\eclipse\jre", "Machine")
[Environment]::SetEnvironmentVariable("JBOSS_DEPLOY", "D:\Entwicklung\Programme\jboss-as\server\default\deploy", "Machine")
[Environment]::SetEnvironmentVariable("JBOSS_HOME", "D:\Entwicklung\Programme\jboss-as", "Machine")
[Environment]::SetEnvironmentVariable("M2_HOME", "D:\Entwicklung\Programme\apache-maven", "Machine")
[Environment]::SetEnvironmentVariable("TOMCAT_HOME", "D:\Entwicklung\Programme\apache-tomcat", "Machine")
[Environment]::SetEnvironmentVariable("ANT_HOME", "D:\Entwicklung\Programme\apache-ant", "Machine")


[System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";D:\Entwicklung\Programme\mysql\bin;D:\Entwicklung\Programme\apache-maven\bin;D:\Entwicklung\Programme\apache-ant\bin;D:\Entwicklung\Programme\eclipse\jre\bin", "Machine")

Open in new window


The last command works fine, the path is set correctly.
But the lines before, where new variables should be created (system-wide and permanently) fail in the skript.
When I execute those commands in a Powershell-session the variables are set.

Has anybody a tip what I`m doing wrong. I`m calling the .ps1-Script in an administrative PowerShell-Session.

Is there a way to execute those commands by right-clicking the scripts.

Thanks a lot
ASKER CERTIFIED SOLUTION
Avatar of Sherif_Talaat
Sherif_Talaat
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Systemadministration
Systemadministration

ASKER

At my computer there is only set the PATH correctly. There is no other Variable like JAVA_HOME getting created.
I want those variables to be permanenty as Machine-variables for all users.

It should Show up in:
RightClick "Computer"->"Properties"->Advanced System Properties"->"Environment variables"-> "System-variables".

I open a Powershel with Right-Click->"Run as administrator" and then start the script from console.

As I said, Editing PATH works, but Creating new Machine-variables doesn`t work.
Avatar of Qlemo
Accessing via  $env:JBOSS_DEPLOY  will not work, use
   [Environment]::GetEnvironmentVariable("JBOSS_DEPLOY","Machine")

instead.