0

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?

1 Answer 1

1
$env:test1 = 'test_value'
$target = 'test1'
$value = Invoke-Expression ('$env:' + $target)
$value
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.