1

i am trying to code in powershell where it needs i use a value of a variable as a variable itself ; is there a proper syntax to do it?

here is the example;

$color = "red"
$red = 1

how can i obtain the value of 1? $($color) $"$color" etc give out the errors.

I can explain more regarding the issue i am working with if needed.

1 Answer 1

4

The syntax isn't very concise, but you can use the Get-Variable cmdlet:

Get-Variable -Name $color -ValueOnly

...or simply...

gv $color -ValueOnly
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.