Solved

Setting new Syste, Variables using PowerShell Skript

Posted on 2012-03-14
3
567 Views
Last Modified: 2012-04-02
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
0
Comment
Question by:Systemadministration
3 Comments
 
LVL 3

Accepted Solution

by:
Sherif_Talaat earned 500 total points
ID: 37721142
I tried your script and it's working smoothly on my computer. All you have to do is make sure that you have full admin privileges.

Review this article .. it might help you if you missed something
Permanent Changes to Environment Variables
0
 

Author Comment

by:Systemadministration
ID: 37724063
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.
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 37734868
Accessing via  $env:JBOSS_DEPLOY  will not work, use
   [Environment]::GetEnvironmentVariable("JBOSS_DEPLOY","Machine")

instead.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OfficeMate Freezes on login or does not load after login credentials are input.
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now