PowerShell: Session Environment Variable

By Xah Lee. Date: . Last updated: .

💡 TIP: Windows environment variable names are case-insensitive.

What is Session Environment Variable

When PowerShell starts, it loads environment variable from the Windows: Registry, and they became session environment variables.

Change to environment variable in current session is temporary. Once you exit shell, the changes are gone.

Show the Value of a Single Environment Variable

$env:path

Show All Environment Variables

# show all environment variables
dir env:
powershell env var 2021-01-24
# show env vars whose name contains path
dir env:*path*

Set Environment Variable for current session

# sets env var named xx for current session
$env:xx = "alice"
# get value of a env var name xx
$env:xx

Remove Environment Variable for current session

# remove the env var xx from the current session
Remove-Item env:xx

PowerShell. Environment Variable