If sometime during a PowerShell session you need to see or to temporarily modify the PATH environment variable, you can type one of these commands:

Copy$env:Path                             # shows the actual content
$env:Path = 'C:\foo;' + $env:Path     # attach to the beginning
$env:Path += ';C:\foo'                # attach to the end
Answer from mloskot on Stack Overflow
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.core › about › about_environment_variables
about_Environment_Variables - PowerShell | Microsoft Learn
To make a persistent change to an environment variable on Windows using the System Control Panel: Open the System Control Panel. Select System. Select Advanced System Settings. Go to the Advanced tab. Select Environment Variables.... Make your changes. Linux and macOS have configuration files and scripts that the operating system uses to set environment variables before starting an application. When running PowerShell as the default (login) shell, you can define environment variables in the global initialization files supported by the operating system.
Discussions

Set a persistent environment variable on a windows 10 computer with PowerShell?
Check out this method: https://docs.microsoft.com/en-us/dotnet/api/system.environment.setenvironmentvariable?view=net-6.0#system-environment-setenvironmentvariable(system-string-system-string-system-environmentvariabletarget) More on reddit.com
🌐 r/PowerShell
12
3
February 3, 2022
Setting local variables in Powershell/CMD
in cmd c:\>set var1 = 777 reference it c:\>echo %var1% In PowerShell PS c:\> $var1 = 777 reference it PS c:\> Write-Host $var1 More on reddit.com
🌐 r/sysadmin
6
0
February 16, 2022
Adding a path to environment variable
$NewPath = "C:\AppFolder\App.exe" $Target = [System.EnvironmentVariableTarget]::Machine [System.Environment]::SetEnvironmentVariable('Path', $env:Path + ";$NewPath", $Target) Then look into Invoke-Command or some such to have it performed on multiple machines. More on reddit.com
🌐 r/PowerShell
6
4
May 3, 2018
What is an environment variable and how is it used?
Processes are running programs and services. There's always one running - Linux shell or Windows Explorer, for example. When you start a program, the new process is a 'child' of the one which started it. If you've never seen this, download Microsoft SysInternals Process Explorer and see the way the running programs are shown in a tree , parent and child processes. Environment Variables date back many decades, and are a few in-memory bits of information which customise "the environment". Open a command prompt and run set or open a PowerShell prompt and run gci env: to see what there are. The most commonly used and configured ones are PATH which is ... when I try to run a command, which folders should the OS look inside to find it? and WINDIR where is Windows installed? And USERPROFILE, where is my data? Thing about them is that they are per-process, and when you start a new process, that inherits the environment variables of the parent process which created it. So you can customise the environment it will start in; give it some settings or config in a standardised simple text way which almost all programming languages and scripts can work with. NB. that you see them in group policy for things like folder redirection, or file moving, you can script to put a file in %USERPROFILE%\README.txt and it will work whether the user profiles are on another drive, or redirected to a server. To see this happen, open a PowerShell window and: C:\> $env:test C:\> Nothing. Then: C:\> $env:test = "Hello" C:\> start powershell a new window opens, in the new window: C:\> $env:test Hello The "Hello" has carried over into the new window, into the environment around the new process. But not every new process, if you open a PowerShell window from the start menu, $env:test will be blank there. Or in a command prompt, echo %test% will be blank. They definitely are not secure in any major way - not encrypted, not secret, not restricted access. The benefit is as you linked "Using an environment variable prevents the key from being written to disk.", they won't need to be written into a config file where they could be checked into source control, copied into backup systems, forgotten about, etc. NB they could still be sent elsewhere with something like crash reporting telemetry. More on reddit.com
🌐 r/PowerShell
7
10
January 22, 2022
🌐
Petri
petri.com › home › powershell › powershell set environment variable – a step-by-step guide
PowerShell Set Environment Variable - A Step-By-Step Guide | Petri
May 5, 2025 - Use .NET class method to set an environment variable (Image Credit: Mike Kanakos/Petri) The default scope for environment variables created by PowerShell is the process scope. This means that the environment variables are accessible only within the current PowerShell session or process. They are not available to other processes or sessions. When you close your PowerShell window / prompt, the environment variables created in that session will be removed.
🌐
LazyAdmin
lazyadmin.nl › home › how to set an environment variable in powershell
How to Set an Environment Variable in PowerShell — LazyAdmin
February 1, 2024 - Learn how to view, set, change or remove env variable in PowerShell. All methods to set an environments variable explained.
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-set-environment-variables-using-powershell
How to Set environment variables using PowerShell?
To add or set the environment variable persistently you need to use the .NET method. To set the environment persistently so they should remain even when close the session, PowerShell uses [System.Environment] class with the SetEnvironmentVariable method for the environment variable to set it persistently.
Find elsewhere
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › how to set environment variables in powershell?
How to Set Environment Variables in PowerShell? - SharePoint Diary
October 7, 2025 - This removes the “My_Var” from the “User” section of environment variables. The script uses the SetEnvironmentVariable method to set the environment variable’s value to null, effectively removing it. Please note that you must start a new session (open a new PowerShell window) for the changed environment variable to take effect.
🌐
PowerShell Test-Path
powershellfaqs.com › set-and-get-environment-variables-in-powershell
How to Set and Get Environment Variables in PowerShell?
September 4, 2024 - For example, to set the variable “MyVariable” to “Hello, World!”, you would use the command $env:MyVariable = "Hello, World!". This method sets the variable temporarily, making it available only in the current PowerShell session. ... Environment variables are dynamic values that affect the way processes and applications run on a computer. They can store information such as file paths, system configurations, and user preferences. In Windows, environment variables can be user-specific or system-wide.
🌐
EDUCBA
educba.com › home › data science › data science tutorials › powershell tutorial › powershell set environment variable
PowerShell set environment variable | Learn the Working with Examples?
March 6, 2023 - Setting the environment variable using the PowerShell is the easy way, and for that, we can use either the simple variable appending method, the .Net method, or the Set-Item cmdlet.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
DEV Community
dev.to › asmitbm › setting-windows-powershell-environment-variables-2glb
Setting Windows PowerShell environment variables - DEV Community
March 7, 2022 - So, I was assigned a task in one of the Open-source project named MetaCall, a super cool tool used for Polyglot programming, where I had to add a path to PATH variable permanently, so even if PowerShell session was over, the path value still stayed in PATH variable, basically to persist it. This is what I came up with after hours of debugging (as I was using PowerShell for the very first time). # Test folder $InstallLocation = "C:\bin" # To add folder to PATH $persistedPath = [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine) -split ';' if ($persistedPath -notc
🌐
ShellHacks
shellhacks.com › home › windows: set environment variable – cmd & powershell
Windows: Set Environment Variable - CMD & PowerShell - ShellHacks
October 28, 2019 - Set an environment variable for the current terminal session: # Windows CMD C:\> set VAR_NAME="VALUE" # Windows PowerShell PS C:\> $env:VAR_NAME="VALUE"
🌐
Adam the Automator
adamtheautomator.com › powershell-environment-variables
PowerShell Environment Variables: A Deep Dive
Running the powershell.exe executable to start a new session, using the ExecutionPolicy command line parameter to set a policy for the session. The PSModulePath environment variable contains the path that PowerShell searches for modules if you do not specify a full path. It is formed much like the standard PATH environment variable, with individual directory paths separated by a semicolon. PS51> $env:PSModulePath C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
Published   October 1, 2023
🌐
Netwrix
netwrix.com › home › resources › blog › powershell environment variables
PowerShell Environment Variables
August 25, 2025 - If the variable is set only in the current session using “$env:”, it will not persist after closing PowerShell. Make sure you are setting the variable at the user or system level using System.Environment class or registry editor. Environment variable names are case-insensitive on Windows, but you might encounter case-sensitivity issues when working with cross-platform scripts such as in PowerShell Core on Linux or macOS.
🌐
TechTarget
techtarget.com › searchitoperations › answer › Manage-the-Windows-PATH-environment-variable-with-PowerShell
Manage the Windows PATH environment variable with PowerShell | TechTarget
The truly permanent and global way to edit the PATH variable is by using .NET with PowerShell launched with administrative privileges. The .NET framework has methods called GetEnvironmentVariable and SetEnvironmentVariable on the System.Environment class.
🌐
ShellGeek
shellgeek.com › home › powershell › set environment variable using powershell
Set Environment Variable using PowerShell - ShellGeek
April 14, 2024 - Using $env:Path variable in PowerShell to set environment variable for the session or temporary. Use [System. Environment] method in PowerShell to set environment variable permanently.
🌐
Sigasi
sigasi.com › knowledge › how_tos › setting-environment-variables
Setting Environment Variables - Sigasi
September 23, 2024 - Enter the variable name and value, then click OK. Note: User variables apply only to the current user, while system variables apply to all users on the machine. Open Command Prompt or PowerShell with administrator rights.
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › how to set environment variable in windows
How to Set Environment Variables in Windows
December 9, 2025 - The method for checking current environment variables depends on whether you are using the Command Prompt or Windows PowerShell: In the Command Prompt, use the following command to list all environment variables: ... Both the Command Prompt and PowerShell use the echo command to list specific environment variables. ... Here, [variable_name] is the name of the environment variable you want to check. Follow the steps to set environment variables using the Windows GUI:
🌐
Configu
configu.com › home › setting environment variables in powershell: a practical guide
Setting Environment Variables in PowerShell: A Practical Guide - Configu
January 17, 2025 - Here are some of the ways that ... variables in PowerShell. Persisting environment variables involves saving them so that they remain available across different sessions. This can be done by modifying the system’s environment settings through the Windows GUI or using scripts ...