Reputation: 13593
Let's say I have an environment variable called test1
whose value is test_value
. How can I display test_value
by using another variable $target='test1'
?
Here are what I've tried:
$target='test1'
echo $env:$target
echo $env:$($target)
echo "$env:$target"
All of the 3 methods above fail to display test_value
. How can I achieve my goal?
Upvotes: 0
Views: 39
Reputation: 43569
$env:test1 = 'test_value'
$target = 'test1'
$value = Invoke-Expression ('$env:' + $target)
$value
Upvotes: 1