Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagepowershell
# Setting a user-level persistent environment variable
[Environment]::SetEnvironmentVariable('PersistentVar', 'Persistent Value', 'User')

# Setting a machine-level persistent environment variable
[Environment]::SetEnvironmentVariable('PersistentVar', 'Persistent Value', 'Machine')

Excerpt
hiddentrue
nameInternal_Note

Internal_Note


Avoid this alternative: Temporary Environment Variable (Session Scope)

To create a temporary environment variable that only exists during the current PowerShell session, you can use the $env: prefix followed by the variable name and its value. For example, to create a variable named TEMP_VAR with the value temp_value, you would use:

Code Block
$env:TEMP_VAR = "temp_value"

This variable will not persist after the PowerShell session ends.