Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - how to set system's environment variable permanently

Reply
 
Old 07-28-2009   #1 (permalink)
Xah Lee


 
 

how to set system's environment variable permanently

How to add a Windows envirenment var permanently with PowerShell?

The PowerShell Cookbook by Lee Holmes says this:

$oldPersonalPath = [Environment]::GetEnvironmentVariable("PATH",
"USER")
$oldPersonalPath += ";d:\tools"
[Environment]::SetEnvironmentVariable("Path", $oldPersonalPath,
"User")

however, when i do

[Environment]::GetEnvironmentVariable("Path", "User")

nothing is returned. Piping it to get-member returns the error: Get-
Member : No object has been specified to get-member.

I can do the following but it's just per session.

$envath = $envath + ";C:\Users\xah\PowerShell scripts\"

A quick search in this group doesn't seems to find answer.

Thanks.

Xah
http://xahlee.org/



My System SpecsSystem Spec
Old 07-28-2009   #2 (permalink)
Larry__Weiss


 
 

Re: how to set system's environment variable permanently

Read this article and especially note the caveat regarding restarting PowerShell.

http://www.microsoft.com/technet/scr...pstip1214.mspx

- Larry


Xah Lee wrote:
Quote:

> How to add a Windows envirenment var permanently with PowerShell?
>
> The PowerShell Cookbook by Lee Holmes says this:
>
> $oldPersonalPath = [Environment]::GetEnvironmentVariable("PATH",
> "USER")
> $oldPersonalPath += ";d:\tools"
> [Environment]::SetEnvironmentVariable("Path", $oldPersonalPath,
> "User")
>
> however, when i do
>
> [Environment]::GetEnvironmentVariable("Path", "User")
>
> nothing is returned. Piping it to get-member returns the error: Get-
> Member : No object has been specified to get-member.
>
> I can do the following but it's just per session.
>
> $envath = $envath + ";C:\Users\xah\PowerShell scripts\"
>
> A quick search in this group doesn't seems to find answer.
>
> Thanks.
>
> Xah
> ∑ http://xahlee.org/
>
> ☄
My System SpecsSystem Spec
Old 07-29-2009   #3 (permalink)
Joel Bennett


 
 

Re: how to set system's environment variable permanently

To set it PERMANENTLY you use SetEnvironmentVariable, but to have it
take effect NOW you need to use the Env: drive.

Write yourself a little script that does both...
--
Joel


Xah Lee wrote:
Quote:

> How to add a Windows envirenment var permanently with PowerShell?
>
> The PowerShell Cookbook by Lee Holmes says this:
>
> $oldPersonalPath = [Environment]::GetEnvironmentVariable("PATH",
> "USER")
> $oldPersonalPath += ";d:\tools"
> [Environment]::SetEnvironmentVariable("Path", $oldPersonalPath,
> "User")
>
> however, when i do
>
> [Environment]::GetEnvironmentVariable("Path", "User")
>
> nothing is returned. Piping it to get-member returns the error: Get-
> Member : No object has been specified to get-member.
>
> I can do the following but it's just per session.
>
> $envath = $envath + ";C:\Users\xah\PowerShell scripts\"
>
> A quick search in this group doesn't seems to find answer.
>
> Thanks.
>
> Xah
> ∑ http://xahlee.org/
>
> ☄
My System SpecsSystem Spec
Old 07-31-2009   #4 (permalink)
Xah Lee


 
 

Re: how to set system's environment variable permanently

Larry__Weiss wrote:
Quote:

> Read this article and especially note the caveat regarding restarting PowerShell.
>
http://www.microsoft.com/technet/scr...pstip1214.mspx

Thanks.
Quote:
Quote:

> > [Environment]::GetEnvironmentVariable("Path", "User")
> > nothing is returned.
apparantly my problem was the wrong variable. There's no “Path” env
var of User category on my machine.

I now try:

[Environment]::GetEnvironmentVariable("Path", "system")

but that's a error. Apparantly the name is not “system”. What should i
put for the second param? It's not clear to me where i'd find this
info. Am still grobing Windows system and docs...

Xah
http://xahlee.org/


My System SpecsSystem Spec
Old 07-31-2009   #5 (permalink)
Larry__Weiss


 
 

Re: how to set system's environment variable permanently

Read the error message in its entirety. Doesn't it tell you what the valid
values are for that second argument?

Were you able to get to the text of this article?
http://www.microsoft.com/technet/scr...pstip1214.mspx

- Larry

Xah Lee wrote:
Quote:
Quote:
Quote:

>>> [Environment]::GetEnvironmentVariable("Path", "User")
>>> nothing is returned.
> apparantly my problem was the wrong variable. There's no “Path” env
> var of User category on my machine.
> I now try:
> [Environment]::GetEnvironmentVariable("Path", "system")
> but that's a error. Apparantly the name is not “system”. What should i
> put for the second param? It's not clear to me where i'd find this
> info. Am still grobing Windows system and docs...
>
> Larry__Weiss wrote:
Quote:

>> Read this article and especially note the caveat regarding restarting PowerShell.
>> http://www.microsoft.com/technet/scr...pstip1214.mspx
>>
My System SpecsSystem Spec
Old 07-31-2009   #6 (permalink)
Xah Lee


 
 

Re: how to set system's environment variable permanently


Xah wrote:
Quote:
Quote:

> > I now try:
> > [Environment]::GetEnvironmentVariable("Path", "system")
> > but that's a error. Apparantly the name is not “system”.. What should i
> > put for the second param? It's not clear to me where i'd find this
> > info. Am still grobing Windows system and docs...
Larry__Weiss wrote:
Quote:

> Read the error message in its entirety. Doesn't it tell you what the valid
> values are for that second argument?
Doh! Thanks.
Quote:

> Were you able to get to the text of this article?http://www.microsoft.com/technet/scr.../pstips/dec07/...
Yes. Did read the whole thing. Thanks.

Xah
http://xahlee.org/


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
environment variable not seen Software
Path Environment Variable - Vista 64-bit Vista General
PATHEXT environment variable and PS1 scripts PowerShell
how to set environment variable where name is not a-z nor A-Z PowerShell
how to set environment variable where name is not a-z nor A-Z PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46