environment variable in powershell
Beside the session scope, an environment variable may be stored with the following scopes:
Get-ChildItem Env:
# or
dir env:
Show the variables that were set permanently before the session and not during the session
$Env:os
Windows_NT
the .NET Framework to return information about a particular environment variable:
[Environment]::GetEnvironmentVariable("Sample","User")
where:
Create and/or set
$env:TestVariable = "This is a test environment variable."
If PowerShell can’t find an environment variable named TestVariable it will automatically create the variable and assign it the specified value.
You need to use the .NET Framework and the SetEnvironmentVariable method.
[Environment]::SetEnvironmentVariable("TestVariable", "Test value.", "User")
where:
Remove-Item Env:\TestVariable
[Environment]::SetEnvironmentVariable("TestVariable",$null,"User")