Reputation: 33
guys..i'm not familiar with PS and at beginning it was a simple question,but it's not so simple for me. (Sorry)
I need to take one environment variable as a string to another env. variable something like this sketch "$env:$env:var" I've tried (of course not working,but helps to understand):
$env:admin1 = "123456"
$env:user = "admin1"
$password = $env:"${env:user}"
Write-Host $password
Is it possible in powershell? Thank you!
Upvotes: 1
Views: 303
Reputation: 3695
It's not possible the way you're doing it, but you can query the environment and match the variable name from a variable a number of different ways. Here's one:
$appData = 'APPDATA'
$value = (Get-ChildItem Env: | ? { $_.Name -eq $appData }).Value
$value # Output
Upvotes: 3