![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| math with "GB/MB/KB" in variables fails, without variables works? | PowerShell | |||
| $Variables | PowerShell | |||
| not using variables | PowerShell | |||