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 - Re: list env variables

Reply
 
Old 01-03-2007   #1 (permalink)
Keith Hill


 
 

Re: list env variables

"Rick" <Rick@discussions.microsoft.com> wrote in message
news:F97D3AF5-93E5-4D24-86A7-D2E326CED85E@microsoft.com...
>Secondly how do you change a variable like
> $HOME, when I try I get "Cannot overwrite variable HOME because it is
> read-only or constant."


Look at using Set-Variable. I believe there is a -force parameter.
Readonly's you can blast over I believe but I'm not sure you do that with a
constant (or perhaps that is reversed). It really frustrating not to have
PoSH installed on this computer. Arrgghh.

--
Keith


My System SpecsSystem Spec
Old 01-04-2007   #2 (permalink)
Rick


 
 

Re: list env variables

Still confused. If I dir env: I get a list Name / Value ( I truncated the
actual list)
Name
----
HOMEDRIVE
HOMEPATH
HOMESHARE
TEMP
TMP
windir

But if I echo the Name nothing is returned


[C:\Powershell]
# echo $HOMEDRIVE
[C:\Powershell]
# echo $HOMESHARE
[C:\Powershell]
# echo $TEMP
[C:\Powershell]
# echo $HOMEPATH

If I echo $HOME a value is returned and HOME isn't even on the list (nor is
$PROFILE).
So is dir env: really showing PS environment or just The Dos environment?
[C:\Powershell]
# echo $HOME
H:\

Rick

"Keith Hill" wrote:

> "Rick" <Rick@discussions.microsoft.com> wrote in message
> news:F97D3AF5-93E5-4D24-86A7-D2E326CED85E@microsoft.com...
> >Secondly how do you change a variable like
> > $HOME, when I try I get "Cannot overwrite variable HOME because it is
> > read-only or constant."

>
> Look at using Set-Variable. I believe there is a -force parameter.
> Readonly's you can blast over I believe but I'm not sure you do that with a
> constant (or perhaps that is reversed). It really frustrating not to have
> PoSH installed on this computer. Arrgghh.
>
> --
> Keith
>

My System SpecsSystem Spec
Old 01-04-2007   #3 (permalink)
Sung M Kim


 
 

Re: list env variables

Comments in-line

Rick wrote:
> Still confused. If I dir env: I get a list Name / Value ( I truncated the
> actual list)
> Name
> ----
> HOMEDRIVE
> HOMEPATH
> HOMESHARE
> TEMP
> TMP
> windir
>
> But if I echo the Name nothing is returned


You can access names and values of environment variables in a couple of
different ways
1.) get-item env:Environment_Variable_Name(returns
System.Collections.DictionaryEntry containing name/value pair)
e.g.)
Code:
==================================================
[^_^]PS[114]>Get-Item env:HOMEDRIVE

Name                           Value
----                           -----
HOMEDRIVE                      C:
==================================================

2.) using $env variable(returns a VALUE of specified environment
variable)
E.G.)
Code:
==================================================
[^_^]PS[115]>$env:HOMEDRIVE
C:
==================================================


> [C:\Powershell]
> # echo $HOMEDRIVE
> [C:\Powershell]
> # echo $HOMESHARE
> [C:\Powershell]
> # echo $TEMP
> [C:\Powershell]
> # echo $HOMEPATH
>
> If I echo $HOME a value is returned and HOME isn't even on the list (nor is
> $PROFILE).


"$" is used for a variable and unless you have created variables named
"$HOMEDRIVE", "$HOMESHARE", etc,
"echo" will not return anything as the following output shows

Code:
==================================================
# "Strict" option will generate error when you try to access a
non-declared variable
[^_^]PS[122]>Set-PSDebug -Strict
[^_^]PS[123]>echo $HOMEDRIVE
The variable $HOMEDRIVE cannot be retrieved because it has not been set
yet.
At line:1 char:15
+ echo $HOMEDRIVE <<<<
[^_^]PS[124]>echo $HOMESHARE
The variable $HOMESHARE cannot be retrieved because it has not been set
yet.
At line:1 char:15
+ echo $HOMESHARE <<<<
[^_^]PS[125]>echo $TEMP
The variable $TEMP cannot be retrieved because it has not been set yet.
At line:1 char:10
+ echo $TEMP <<<<
[^_^]PS[126]>echo $HOMEPATH
The variable $HOMEPATH cannot be retrieved because it has not been set
yet.
At line:1 char:14
+ echo $HOMEPATH <<<<
[^_^]PS[127]>$TEMP = "some temporary string"
[^_^]PS[128]>echo $TEMP
some temporary string
==================================================

> So is dir env: really showing PS environment or just The Dos environment?

This, i am not sure of...

My System SpecsSystem Spec
Old 01-04-2007   #4 (permalink)
Keith Hill [MVP]


 
 

Re: list env variables

"Rick" <Rick@discussions.microsoft.com> wrote in message
news:89021B71-06C3-4613-A0C8-3187FEBC3F25@microsoft.com...
> So is dir env: really showing PS environment or just The Dos environment?


A quick experiment indicates that dir env: shows the enivornment variables
that PowerShell was launched with.

--
Keith


My System SpecsSystem Spec
Old 01-04-2007   #5 (permalink)
Rick


 
 

Re: list env variables

Thanks All that helps!

"Keith Hill [MVP]" wrote:

> "Rick" <Rick@discussions.microsoft.com> wrote in message
> news:89021B71-06C3-4613-A0C8-3187FEBC3F25@microsoft.com...
> > So is dir env: really showing PS environment or just The Dos environment?

>
> A quick experiment indicates that dir env: shows the enivornment variables
> that PowerShell was launched with.
>
> --
> Keith
>
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
math with "GB/MB/KB" in variables fails, without variables works? PowerShell
$Variables PowerShell
not using variables 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