I would like to dynamically construct the name of an environment variable. I tried this:
$partition = $env:partition
$desiredvariable = "abc_$partition"
$desiredvalue = $env:$desiredvariable
This doesn't seem to work. Can this be done?
Thanks
Environment variables can be manipulated using the [System.Environment]::SetEnvironmentVariable() method:
$SomeName = "test"
[System.Environment]::SetEnvironmentVariable($SomeName,"value")
You can then access it like normally:
PS C:\> $env:test
value
Or, using the GetEnvironmentVariable() method:
PS C:\> [System.Environment]::GetEnvironmentVariable($SomeName)
value
PS C:\> [System.Environment]::GetEnvironmentVariable("test")
value