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 Tutorial - Creating A Variable from the Value of Another

Reply
 
Old 08-09-2007   #1 (permalink)
Luke
Guest


 
 

Creating A Variable from the Value of Another

I want to be able to create a variable from the value of another variable.
For example, say that $a=example1. How could I create a variable named
$example1 by using the data from $a?

My System SpecsSystem Spec
Old 08-09-2007   #2 (permalink)
Kiron
Guest


 
 

Re: Creating A Variable from the Value of Another

Use Set-Variable:

Set-Variable -name $a -value 'new value'


--
Kiron
My System SpecsSystem Spec
Old 08-09-2007   #3 (permalink)
Shay Levi
Guest


 
 

Re: Creating A Variable from the Value of Another

PS C:\Scripts> $a="hello"
PS C:\Scripts> New-Variable -name "$a" -value " world"
PS C:\Scripts> $hi
world

Shay
http://scriptolog.blogspot.com



> I want to be able to create a variable from the value of another
> variable. For example, say that $a=example1. How could I create a
> variable named $example1 by using the data from $a?
>



My System SpecsSystem Spec
Old 08-09-2007   #4 (permalink)
Shay Levi
Guest


 
 

Re: Creating A Variable from the Value of Another

sorry had a typo

$a="hello"
New-Variable -name "$a" -value " world"
$hello
world


Shay
http://scriptolog.blogspot.com



> PS C:\Scripts> $a="hello"
> PS C:\Scripts> New-Variable -name "$a" -value " world"
> PS C:\Scripts> $hi
> world
> Shay
> http://scriptolog.blogspot.com
>> I want to be able to create a variable from the value of another
>> variable. For example, say that $a=example1. How could I create a
>> variable named $example1 by using the data from $a?
>>



My System SpecsSystem Spec
Old 08-09-2007   #5 (permalink)
A. Petitjean
Guest


 
 

RE: Creating A Variable from the Value of Another

Hi Luke,

You can also try this technique :
$a="example1"
$i=10
Invoke-Expression "`$$a = $i"

Best regards,

Arnaud Petitjean
http://www.powershell-scripting.com
The french PowerShell Community

"Luke" wrote:

> I want to be able to create a variable from the value of another variable.
> For example, say that $a=example1. How could I create a variable named
> $example1 by using the data from $a?

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
creating Environment variable during logon script VB Script
$Variable Is In {1,2,3,4} PowerShell
Creating objects with variable names in functions PowerShell
tab and variable PowerShell
How can I ensure that a variable is a built-in powershell variable? 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