Solved

Setting new Syste, Variables using PowerShell Skript

Posted on 2012-03-14
3
585 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 69

Expert Comment

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

instead.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

You may have a outside contractor who comes in once a week or seasonal to do some work in your office but you only want to give him access to the programs and files he needs and keep privet all other documents and programs, can you do this on a loca…
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
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…
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

756 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