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 environment variable where name is not a-z nor A-Z

Reply
 
Old 12-04-2006   #1 (permalink)
hieulugia@gmail.com


 
 

how to set environment variable where name is not a-z nor A-Z

i need to set source.dir environment variable in my scripts, if I use

$env:source.dir=c:\source

i got error like "Property 'dir' cannot be found on this object."

Some one please help, thanks!


My System SpecsSystem Spec
Old 12-04-2006   #2 (permalink)
Andrew Watt [MVP]


 
 

Re: how to set environment variable where name is not a-z nor A-Z

On 4 Dec 2006 11:43:45 -0800, hieulugia@gmail.com wrote:

>i need to set source.dir environment variable in my scripts, if I use
>
>$env:source.dir=c:\source
>
>i got error like "Property 'dir' cannot be found on this object."
>
>Some one please help, thanks!


The following should do what you want.

cd env:
new-item -path "source.dir" -value "C:\Source"

or

new-item -path "env:\source.dir" -value "C:\Source"

Andrew Watt MVP
My System SpecsSystem Spec
Old 12-04-2006   #3 (permalink)
Bruce Payette [MSFT]


 
 

Re: how to set environment variable where name is not a-z nor A-Z

Or, more simply:

${env:source.dir} = "c:\source"

Note that this also works with regular variables:

${variable with spaces} = "foo"

and even with files:

PS (1) > ${c:\a file.txt} = "Hello"
PS (2) > get-content "c:\a file.txt"
Hello

-bruce

--
Bruce Payette [MSFT]
Windows PowerShell Technical Lead
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.


"Andrew Watt [MVP]" <SVGDeveloper@aol.com> wrote in message
news:hvu8n21aurkrughc0r41ta1en4kuv4v9om@4ax.com...
> On 4 Dec 2006 11:43:45 -0800, hieulugia@gmail.com wrote:
>
>>i need to set source.dir environment variable in my scripts, if I use
>>
>>$env:source.dir=c:\source
>>
>>i got error like "Property 'dir' cannot be found on this object."
>>
>>Some one please help, thanks!

>
> The following should do what you want.
>
> cd env:
> new-item -path "source.dir" -value "C:\Source"
>
> or
>
> new-item -path "env:\source.dir" -value "C:\Source"
>
> Andrew Watt MVP



My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
how to set system's environment variable permanently PowerShell
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


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