如何将变量的值用作变量本身?

时间:2012-12-13 16:00:24

标签: variables powershell nested

我试图在powershell中编码,它需要我将变量的值用作变量本身;有没有正确的语法呢?

这是示例;

$color = "red"
$red = 1

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

如果需要,我可以解释一下我正在处理的问题。

1 个答案:

答案 0 :(得分:4)

语法不是很简洁,但您可以使用Get-Variable cmdlet

Get-Variable -Name $color -ValueOnly

......或者只是......

gv $color -ValueOnly