/
/

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 variable PowerShell variable Description
%ALLUSERSPROFILE% $env:ALLUSERSPROFILE Shared app data across all users
%APPDATA% $env:APPDATA Roaming application data folder
%COMPUTERNAME% $env:COMPUTERNAME Hostname of the local machine
%OneDrive% $env:OneDrive OneDrive folder path (if OneDrive is installed)
%PATH% $env:PATH Executable search path for processes
%PROGRAMFILES% $env:ProgramFiles Default directory for 64-bit app installations
%SystemDrive% $env:SystemDrive Drive where Windows is installed
%SYSTEMROOT% $env:SystemRoot Path to Windows directory
%TEMP% or %TMP% $env:TEMP or $env:TMP Temporary file location
%USERNAME% $env:USERNAME Your Windows username
%USERPROFILE% $env:USERPROFILE Current 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?
×

See NinjaOne in action!

By submitting this form, I accept NinjaOne's privacy policy.

NinjaOne Terms & Conditions

By clicking the “I Accept” button below, you indicate your acceptance of the following legal terms as well as our Terms of Use:

  • Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms.
  • Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party.
  • Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library belonging to or under the control of any other software provider.
  • Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations.
  • Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks.
  • Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script.
  • EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).