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?
gi c:file.txt,gi variable:v0,gi env:path, etc. Similarly these:${c:file.txt},${variable:v0},${env:path}also get an item. In last 2 you can omit braces. This illustrates paths but doesn't answer your question. For that u have 2 use provider specific cmdlets: get-variable and get-alias. They take names created by concatenation