-1

I am wondering if it is possible to reference a variable in powershell by concatonating two or more pieces of data. See example below...

$v0 = "My Var"
$v1 = "My Var2"

$suffix = 0

#THESE EXAMPLES BELOW (ALTHOUGH WRONG) WILL ILLUSTRATE WHAT WE ARE TRYING TO DO.

Write-Host $(v($suffix)) #ERROR
Write-Host $(v$suffix) #ERROR
Write-Host v$suffix # "v0"

I would like this script to output "My Var". I do not think this is possible since Powershell is using .NET which is not a dynamic language. Any ideas if this is possible?

4

1 回答 1

2
Write-Host (Get-Variable "v$suffix" -ValueOnly)
于 2013-07-10T16:09:54.613 回答