Solved

Setting new Syste, Variables using PowerShell Skript

Posted on 2012-03-14
3
564 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
A procedure for exporting installed hotfix details of remote computers using powershell
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…

744 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

12 Experts available now in Live!

Get 1:1 Help Now