/
/

How to View and Manage Environment Variables in Windows

How to View and Manage Environment Variables in Windows blog banner image

Environment variables are dynamic values Windows and applications use to define system paths, configuration settings, and user-specific data. These variables are commonly referenced in scripts, command-line tools, installers, and application runtime environments.

Properly managing environment variables allows you to standardize user and system-level paths and simplify deployment and script portability. It also helps you troubleshoot apps or script failures caused by misconfigured variables and control runtime settings for development and automation tools.

This guide will walk you through several ways to view and manage environment variables in Windows 11.

Note: The instructions in this guide apply to both Windows 10 and Windows 11. The tools, command-line syntax, and environment variable structure are consistent across both versions, with only minor cosmetic differences in UI. Whether you’re managing variables through the GUI, Command Prompt, or PowerShell, the process remains the same.

How to view and manage environment variables

Before proceeding, here are key points to keep in mind:

  • Editing system-wide variables requires administrative privileges.
  • Environment variable changes may require a reboot or sign-out to take full effect.
  • Incorrect edits to critical variables (e.g., PATH) can cause application failures. Always back up existing values before making changes.

Method 1: View and edit environment variables via GUI

This is the simplest method, ideal for beginners or users who prefer a graphical interface.

  1. Right-click the Start button and select System.
  2. On the right panel, click Advanced system settings.
  3. In the System Properties window, click the Environment Variables button.
  4. You’ll now see two sections:
    • User variables – Apply only to the currently logged-in user.
    • System variables – Apply to all users and processes on the system. (Note: Admin access needed)

To add or edit variables

  • Select a variable, then click Edit to change it.
  • Click New to create a new variable.
  • Click Delete to remove a selected variable.
  • Confirm changes by clicking OK.

Method 2: View environment variables via Command Prompt

This method is fast and helpful for quick checks and script-based automation.

  1. Press Win + R to open the Run dialog box.
  2. Type cmd and click Enter to open the Command Prompt.
  3. To view all current environment variables: Type set and press Enter.
  4. To view a specific variable: Type echo %VARIABLE_NAME% and press Enter.
    For example: echo %PATH%
  5. To define a temporary variable (valid only for the session):
    Type set MY_VAR=TestValue and press Enter.

This is ideal for temporary overrides or script-based testing. However, it won’t persist once you close the Command Prompt.

Method 3: View and edit environment variables via PowerShell

This method offers more flexibility and control over environment variables. It is useful for both temporary and permanent changes.

  1. Press Win + S to open the search.
  2. Type PowerShell, then:
    • Right-click Windows PowerShell and select Run as administrator if you’re setting system-wide variables.
    • Open normally if you’re setting temporary or user-level changes.
  3. To list all environment variables
    • Type Get-ChildItem Env: and press Enter.
  4. To view a specific variable
    • Type $Env:VARIABLE_NAME and press Enter.
    • For example: $Env:Path
  5. To set a new variable (session only)
    • Type $Env:MY_VAR = “TestValue” and press Enter.
  6. ⚠️ This variable is only available in the current PowerShell session. Closing PowerShell removes the variable.
  7. To permanently set user or system environment variables
    • Type [System.Environment]::SetEnvironmentVariable(“MY_VAR”, “TestValue”, “User”) and press Enter.
  8. For system-wide changes (requires admin rights):
    • Type [System.Environment]::SetEnvironmentVariable(“MY_VAR”, “TestValue”, “Machine”) and press Enter.

Remember: Use “User” for variables that apply only to your account or “Machine” for variables that apply to the entire system.

Common environment variables in Windows

Note: This list can be extended using scripting to capture all current values.

Command variablePowerShell variableDescription
%ALLUSERSPROFILE%$env:ALLUSERSPROFILEShared app data across all users
%APPDATA%$env:APPDATARoaming application data folder
%COMPUTERNAME%$env:COMPUTERNAMEHostname of the local machine
%OneDrive%$env:OneDriveOneDrive folder path (if OneDrive is installed)
%PATH%$env:PATHExecutable search path for processes
%PROGRAMFILES%$env:ProgramFilesDefault directory for 64-bit app installations
%SystemDrive%$env:SystemDriveDrive where Windows is installed
%SYSTEMROOT%$env:SystemRootPath to Windows directory
%TEMP% or %TMP%$env:TEMP or $env:TMPTemporary file location
%USERNAME%$env:USERNAMEYour Windows username
%USERPROFILE%$env:USERPROFILECurrent user’s profile directory

Additional considerations

Before managing environment variables in Windows, it’s crucial to understand a few key points. These will help you avoid common mistakes and make the most of environment variables to streamline your scripts and workflows:

PATH management

The PATH environment variable tells the system where to look for executable files when running commands. Tools like PowerShell, Java, Python, or Git automatically add their directories to PATH so they can be run from anywhere in the system.

Accidentally removing or overwriting PATH entries can break core functionality and disable essential tools like cmdping, or ipconfig. To avoid this, always append new paths instead of replacing existing ones. Use a semicolon (;) to separate each entry.

⚠️ Warning: Modifying the system PATH requires administrator privileges. Always back up the original value before making changes.

Deployment

Environment variables play a key role in automating scripts and system provisioning. Instead of hardcoding values, you can reference environment variables to create flexible, reusable scripts that adapt to different users and systems.

This is especially useful in batch scripts and deployment workflows, helping reduce errors and save time during setup.

Script portability

Use environment variables like %~dp0, %USERPROFILE%, and others in your logon scripts or automation tasks to avoid hardcoding paths. %USERPROFILE% points to the current user’s folder, while %~dp0 refers to the script’s own location. These dynamic variables adapt to the current user or system, making your scripts portable.

Session awareness

Variables set using the set command in Command Prompt or $Env: in PowerShell are temporary, and they only exist during the current session. Once the window is closed, the variables disappear.

To make them permanent, they must be written to the system or user environment settings using tools like PowerShell or the Environment Variables GUI.

Managing Windows environment variables effectively

Environment variables are critical for system configuration and automation in Windows 11. They are commonly used in scripting, application compatibility, or deployment to ensure a stable and consistent environment across user sessions and endpoints. You can manage environment variables through the GUI, Command Prompt, or PowerShell, each offering flexibility for scripting and system configuration.

Be cautious when editing system-level variables, especially PATH, as incorrect changes can lead to serious issues. Moreover, it’s essential to understand which variables apply per session, per user, or system-wide to avoid unintended behavior. For standardized deployment, consider automating environment variable setup with PowerShell or batch scripts.

You might also like

Ready to simplify the hardest parts of IT?