Return value of environment variable with powershell

后端 未结 2 1584
遇见更好的自我
遇见更好的自我 2021-01-20 05:03

I have the name of an environment variable in a variable and I want to get the value. How do I do that? I\'ve tried:

PS C:\\Users\\Joe> $v=\"USERDOMAIN\"
         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-20 05:52

    Two lines

    $v = "Path"
    (get-item env:$v).Value
    

    One line

    iex ('$env:' + $x)
    

提交回复
热议问题