0

In PHP I can write that code:

$var = 1;
$name = 'var';
$$name = 2;
echo "var = $var";

Result: var = 2

How can I do things like that in PowerShell?

I tried:

  • $$name = 2
    Unexpected token 'name' in expression or statement.
  • ${$name} = 2
    Creates variable with name $name
0

1 Answer 1

0

You can accomplish this by assigning a variable by reference.

$var = 1
$name = [ref]$var
$name.Value = 2
$var # outputs 2
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.