I want to use indirect reference variable. I am setting this at Command Prompt
SET RiskScheduler=true
My code is like this
Write-Host "$Env:RiskScheduler" # prints true
I want to achieve the same should be printed with code like this
$name='RiskScheduler'
Write-host $name # prints RiskScheduler
Write-Host $Env:$name # gives error
The error I am getting is
Cannot process argument because the value of argument "path" is invalid. Change the value of the "path" argument and run the operation again. At D:mpuildtoolsudclient.6.2ud_clean.PS1:37 char:17 + Write-Host $Env: <<<< `$name` + CategoryInfo : InvalidArgument: (:) [], PSArgumentException + FullyQualifiedErrorId : Argument
I am looking for something that shall first evaluate $name
and then evaluate $Env:(value of $name)
.
Can someone please suggest, what the correct syntax is?
See Question&Answers more detail:os