Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Setting new Syste, Variables using PowerShell Skript

Posted on 2012-03-14
3
Medium Priority
?
599 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 1000 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 71

Expert Comment

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

instead.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.

963 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