47

I'm having this weird situation :

My user's and system's PATH variable is different than the PATH in powershell.

When I do :

PS C:\$env:path C:\Windows\System32\WindowsPowerShell\v1.0\;c:\oldpath 

However this is not correct, it looks like it stuck on some old PATH variable of my system, so none of the udpates I've done on it didn't change this variable (I do restart after every change to test).

Why is this happening? Do I have to set a PATH variable just for powershell?

4
  • How are you changing the path? Just changing it with $env:Path = foo won't persist across sessions. Commented Feb 13, 2009 at 16:30
  • I'm changing the PATH from Computer properties as usual not from console. Commented Feb 13, 2009 at 16:51
  • So you set the path then restart your powershell session and it is not what you changed it to? Commented Feb 13, 2009 at 17:02
  • 2
    no it doesn't, I've restarted it after every test Commented Feb 13, 2009 at 17:12

2 Answers 2

75

The change might be "delayed", so try one or more of these solutions:

  • Log off and on again;
  • Task Manager > Restart "Windows Explorer" (explorer.exe)
  • Restart your launcher app (launchy, SlickRun, etc)
  • Reboot

Explanation:
Powershell will inherit the environment of the process that launched it (which depends on how you launch it). This is usually the interactive shell (explorer.exe). When you modify the environment from computer properties, you modify the environment of explorer.exe, so if you launch powershell from explorer.exe, (for example from the start menu) you should see the new environment.

However, if you launch it from something else (say a cmd.exe shell that you already had opened), then you won't since that process was launched under the old environment.

In other words: be careful how you are launching things.

Sign up to request clarification or add additional context in comments.

2 Comments

In my case the state of the Powershell window in VS Code was retained even between reboots. When I finally actively terminated the Powershell window within VS Code and repopened it, it got the new updated system path-variable.
Task Manager > Restart "Windows Explorer" solved my problem. I can't believe I had to do that.
5

In my case, I installed an app that incorrectly added itself to the PATH by creating a powershell profile that would override $env:PATH and blow out the existing configuration every time I started powershell.

Check if you have profile at USER\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 and if it's doing anything fishy like setting $env:PATH.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.