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?
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?
Use Set-Variable:
Set-Variable -name $a -value 'new value'
--
Kiron
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?
>
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?
>>
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?
| Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| creating Environment variable during logon script | Elgordo | VB Script | 1 | 15 Dec 2008 |
| $Variable Is In {1,2,3,4} | C S S | PowerShell | 3 | 23 Oct 2008 |
| Creating objects with variable names in functions | Frank | PowerShell | 4 | 14 Apr 2007 |
| Set-Variable | Fred J. | PowerShell | 3 | 25 Oct 2006 |
| How can I ensure that a variable is a built-in powershell variable? | Sung M Kim | PowerShell | 7 | 22 Sep 2006 |