Return value of environment variable with powershell

后端 未结 2 1589
遇见更好的自我
遇见更好的自我 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:54

    To complement Vladimir's helpful answer with a solution that makes direct use of the .NET framework:

    $v="USERDOMAIN"
    [Environment]::GetEnvironmentVariable($v) 
    

提交回复
热议问题