To add a folder to your PATH permanently, append it to the User PATH from PowerShell. This needs no administrator window and does not touch the system PATH:
$new = 'C:\Tools'
$user = [Environment]::GetEnvironmentVariable('Path', 'User')
if (($user -split ';') -notcontains $new) {
[Environment]::SetEnvironmentVariable('Path', "$user;$new", 'User')
}Change C:\Tools to your folder. The if means running it twice does not add the folder twice. The change applies to programs started after it, so open a new terminal. It works the same in PowerShell 7 and Windows PowerShell 5.1.
Check first. If Get-Command finds the program, its folder is already on PATH and there is nothing to add. SSMS 22 is one: its installer puts itself on the Machine PATH, so ssms already opens it from a terminal.

Use It in the Current Window Now
A permanent change does not reach windows that are already open. To use the folder straight away in this one, add it to this session as well:
$env:Path += ";$new"
# or reload both saved values into this session
$env:Path = [Environment]::GetEnvironmentVariable('Path','Machine') + ';' + [Environment]::GetEnvironmentVariable('Path','User')The first line changes this window only. Nothing is saved, and it is gone when the window closes.
User or Machine?
User PATH applies to your account only and needs no elevation. Machine PATH applies to every account and every service, and needs PowerShell opened as Administrator:
$machine = [Environment]::GetEnvironmentVariable('Path', 'Machine')
[Environment]::SetEnvironmentVariable('Path', "$machine;$new", 'Machine')Use User unless a service or other users have to find the program. Always read the scope you are writing to. Never build the new value from $env:Path: that is the Machine and User PATH joined together, and writing it back copies the machine entries into your user PATH.
The Settings Window
- Press the Windows key, type environment variables and open Edit the system environment variables.
- Click Environment Variables.
- In the top box (User variables) select Path, then Edit. The bottom box is the Machine PATH.
- Click New, paste the folder, then OK on every window.
- Open a new terminal.



Avoid setx
setx Path "%Path%;C:\Tools" is the answer you will find most often, and it is the one to avoid. Microsoft’s documentation says setx has a limit of 1024 characters and crops anything longer. On a PATH that is already long, it can silently cut the end off. And %Path% is the Machine and User PATH joined, so writing it back copies every machine folder into your user PATH. Use the PowerShell method above, or the window.
Check That It Worked
# is the folder in the saved User PATH?
[Environment]::GetEnvironmentVariable('Path','User') -split ';'
# in a NEW window, can PowerShell find the command?
Get-Command mytoolHow It Works
PATH is a text list of folders, stored once for the machine and once for your user, and each program reads it only when it starts. That is why the change needs a new window, and why a command can still be “not recognized” in a window that was already open. The Machine and User lists are joined to make the PATH you see in a session.
Common Questions
Do I need to restart the computer?
No. Open a new terminal. Programs that were started before the change, such as VS Code, keep the old PATH until you restart them.
How do I remove a folder I added?
Read the User PATH, filter the folder out and write it back, or delete the row in the Environment Variables window:
$dup = 'C:\Tools'
$user = ([Environment]::GetEnvironmentVariable('Path','User') -split ';') | Where-Object { $_ -and $_ -ne $dup }
[Environment]::SetEnvironmentVariable('Path', ($user -join ';'), 'User')
Should the folder go at the start or the end?
Windows searches PATH in order. At the end is safe. At the start, your folder wins over anything with the same name further down.
Related
If SQL Server is part of your day job, my current work lives over at sqldba.blog: production DBA scripts, an error library and the SSMS guide.
Leave a Reply