2012-12-13 26 views
1

我想在PowerShell代碼中它需要我使用一個變量的值作爲變量本身;有沒有適當的語法來做到這一點?如何將變量的值本身用作變量?

這裏是例子;

$color = "red" 
$red = 1 

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

我可以解釋更多關於如果需要我正在處理的問題。

回答

4

的語法不是很簡潔,但是你可以使用Get-Variable cmdlet

Get-Variable -Name $color -ValueOnly 

...或者乾脆...

gv $color -ValueOnly