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 change values in the Machine or User scopes, you must use the methods of the System.Environment class. To make changes to Machine-scoped variables, you must also have permission. If you try to change a value without sufficient permission, the command fails and PowerShell displays an error.
Discussions

How can I get and change environment variables' value in Windows Powershell
Discussed in #9473 Originally posted by xiaolinggnb August 16, 2024 I'm using Windows 11 and willing to get the environment variable value of gh and change them in Windows Powershell, which are lis... More on github.com
🌐 github.com
1
1
Change Environment Path and MAKE IT STICK
See https://www.reddit.com/r/PowerShell/comments/1c4ds4x/comment/kzn7au6/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button as to why you shouldn't use SetEnvironmentVariable for PATH like env vars. The reason why this isn't working is because SetEnvironmentVariable defaults to the process scoped env vars so this is the same as doing $env:PATH = "new value". You can call the overload where you set the Machine scoped vars but see my above comment as to why you don't use to use that. Also as mentioned by u/BlackV entries in the C:\Program Files\WindowsApps folder should not be on the PATH directly. These entries are installed per user which then adds an App Execution Alias in %LOCALAPPDATA%\Microsoft\WindowsApps which is in the user's `PATH` scoped envvar. You should be ensuring that winget is installed for that user and provisioned as part of the default user profile so new user profiles will get it by default. More on reddit.com
🌐 r/PowerShell
11
5
April 15, 2024
env and environment variables in Powershell
$env is a powershell object just like $true. If you want to set an environment variable there's 2 normal ways to do it, one using $env, the second using [Environment]::SetEnvironmentVariable Using $env will only set the variable for the current powershell process, whereas using [Environment]::SetEnvironmentVariable you can set it for different areas (process, user, or machine). When you do $INCLUDE you're not setting an environment variable, you're just creating a variable called $INCLUDE. see http://technet.microsoft.com/en-us/library/ff730964.aspx More on reddit.com
🌐 r/PowerShell
5
8
December 7, 2014
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
People also ask

How to set an environment variable using PowerShell?

To set an environment variable, you can use the following syntax.

$Env:VariableName = “Value”

Replace VariableName with the desired name of your variable and Value with the value you want to assign to it, as example below.

$Env:MY_VAR = “MyValue”

🌐
netwrix.com
netwrix.com › home › resources › blog › powershell environment variables
PowerShell Environment Variables
How do I list all variables in PowerShell?

To list all variables in your PowerShell session, you can use:

Get-ChildItem Env:

This command will show all currently defined variables in the session, including environment variables.

🌐
netwrix.com
netwrix.com › home › resources › blog › powershell environment variables
PowerShell Environment Variables
How to check if an environment variable exists in PowerShell?

To check if a specific environment variable exists, you can use the following command.

Test-Path Env:MY_VAR Replace MY_VAR with the name of the environment variable you want to check. If the variable exists, it will return True; if not, it will return False.

🌐
netwrix.com
netwrix.com › home › resources › blog › powershell environment variables
PowerShell Environment Variables
🌐
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 - In this step-by-step guide, we’ll explore what environment variables are, their scopes, and how to set environment variables using PowerShell. Environmental variables often contain critical configuration information for the operating system and its modules, such as current user information, directory paths, or the location of certain core files for the operating system to function.
🌐
Netwrix
netwrix.com › home › resources › blog › powershell environment variables
PowerShell Environment Variables
August 25, 2025 - PowerShell environment variables ... and scripts. They can be listed with Get-ChildItem Env:, accessed with $Env: , modified with Set-Item or [Environment]::SetEnvironmentVariable(), and removed with Remove-Item....
🌐
LazyAdmin
lazyadmin.nl › home › how to set an environment variable in powershell
How to Set an Environment Variable in PowerShell — LazyAdmin
February 1, 2024 - Note To add or change variables in the machine scope, you will need to have elavated permissions. Run PowerShell in elevated (admin) mode, otherwise you get the error “Requested registry access is not allowed.” · [System.Environment]::SetEnvironmentVariable('TenantId','11e1234-28gv-4413-aaf8-a1e8b7f4c3d6', 'Machine')
Find elsewhere
🌐
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.
🌐
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 - To add or update an environment variable, You can use the SetEnvironmentVariable () method. The syntax for adding or updating an environment variable with .Net Framework method “SetEnvironmentVariable” is as below: ... # PowerShell to set ...
🌐
ShellGeek
shellgeek.com › home › powershell › set environment variable using powershell
Set Environment Variable using PowerShell - ShellGeek
April 14, 2024 - $env:Path in PowerShell to set environment variable for the session or temporary.[System. Environment] set environment variable permanently.
🌐
Hosting Ultra So
hostingultraso.com › help › windows › view-modify-environment-variables-powershell
View and Modify Environment Variables in PowerShell | Windows PowerShell, Windows Server | HostingUltraso.com
Problem You want to interact with your system’s environment variables. Solution To interact with environment variables, access them in almost the same way that you access regular PowerShell variables. The only difference is that you place env: between the ($) dollar sign and the variable name: PS >$env:Username Lee You can modify environment variables this way, too.
🌐
Powershellcookbook
powershellcookbook.com › recipe › ZVHx › view-and-modify-environment-variables
PowerShell Cookbook - View and Modify Environment Variables
PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\Invoke-DemonstrationScript.ps1". See "get-help about_Command_Precedence" for more details. PS > $env:PATH = $env:PATH + ".;" PS > Invoke-DemonstrationScript The script ran! In batch files, environment variables are the primary way to store temporary information or to transfer information between batch files.
🌐
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.
🌐
TheITBros
theitbros.com › home › windows › managing environment variables in windows with powershell
How to Manage Windows Environment Variables with PowerShell
January 7, 2026 - In Windows, the operating system ... Users can use the Control Panel graphical interface (SystemPropertiesAdvanced.exe > Environment Variables) or the PowerShell console to add, edit, or delete environment variables and their values....
🌐
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"
🌐
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
🌐
GitHub
github.com › cli › cli › discussions › 9475
How can I get and change environment variables' value in Windows Powershell · cli/cli · Discussion #9475
If you'd like the variable to be more permanent, you should add it to your .bashrc, .bash_profile, or similar so it gets exported every time you start a new shell session. Here's some Microsoft documentation about managing environment variables on Windows, if that's the environment you are using.
Author   cli
🌐
Reddit
reddit.com › r/powershell › change environment path and make it stick
r/PowerShell on Reddit: Change Environment Path and MAKE IT STICK
April 15, 2024 -

Hi all,

We've got an odd issue where random machines (all Win11) cannot run Winget, even though it's installed. I've identified the cause as being Winget isn't included in the PATH environment variable. Now I've got a script written for this (as an Intune Remediation), but in testing this won't stick.

Found an article about setting this to the Machine context, but not sure if I'm doing it right because it still won't goddamned stick. Script below - can anyone assist with this?

# Get winget path into variable
$wingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
 # Extract PATH into separate values
$pathParts = $env:PATH -split ';'
# Append winget path to PATH values
$addToPath = $pathParts + $wingetPath | Where-Object { $_ }
# Reconstitute and set PATH with new variables
$newEnvPath = $addToPath -join ';'
[System.Environment]::SetEnvironmentVariable('PATH',$newEnvPath)

🌐
Delft Stack
delftstack.com › home › howto › powershell › powershell refresh environment variables
How to Set Environment Variables Using PowerShell | Delft Stack
February 22, 2024 - We can both make or modify an environment variable. ... We use the PowerShell cmdlet Set-Item to modify the value of an existing environment variable named TEST within the Env:\ namespace.