Introduction
Environment variables store information that programs and scripts can use to work properly. They help scripts know about the system or user settings without hardcoding values.
Get-ChildItem Env:\
$env:VARIABLE_NAME = "value"
$env:VARIABLE_NAMEGet-ChildItem Env:\ to list all environment variables.$env:VARIABLE_NAME to read or set an environment variable.Get-ChildItem Env:\
$env:USERNAME
$env:MY_VAR = "Hello"
Write-Output $env:MY_VAR$env:GREETING = "Hello, PowerShell!" Write-Output "The greeting is: $env:GREETING" # List a few important environment variables Write-Output "User: $env:USERNAME" Write-Output "Home Path: $env:HOMEPATH"
$env:VARIABLE_NAME = $null to remove an environment variable in the current session.$env:VARIABLE_NAME to read or write environment variables in PowerShell.PATH in PowerShell?$env:VARIABLE_NAME to access environment variables.$env:PATH.MY_VAR to the value hello in PowerShell?$env:VariableName to a value.$env:MY_VAR = 'hello' to set the variable.$env:GREETING = 'Hello' Write-Output "$env:GREETING, World!"
$env:GREETING = 'Hello' sets the environment variable GREETING to 'Hello'.Write-Output "$env:GREETING, World!" expands $env:GREETING to 'Hello', so the output is 'Hello, World!'.Write-Output $envMY_VAR
$envMY_VAR is invalid because environment variables require a colon after env, like $env:MY_VAR.Write-Output $env:MY_VAR to properly access the environment variable.C:\Tools to the PATH environment variable for your current PowerShell session only. Which command correctly does this?$env:PATH directly changes it only for the current session.$env:PATH = $env:PATH + ';C:\Tools' to add the folder, separating with a semicolon.Pass the test and this pattern moves unknown