Reputation: 427
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.
Upvotes: 1
Views: 227
Reputation: 16596
The syntax isn't very concise, but you can use the Get-Variable
cmdlet:
Get-Variable -Name $color -ValueOnly
...or simply...
gv $color -ValueOnly
Upvotes: 4