'Powershell 5.0 doesn't see PATH environment variables under User account

I added an environment variable to my System Path -> C:\Program Files\TEE-CLC. After that, I expect, that I can run my foo.exe which is under C:\Program Files\TEE-CLC from PowerShell without providing a full path to it. The issue is when I start a new, fresh Powershell session under my user, it doesn't see the newly added path, but when I start it under administrator everything works fine.

I checked $env:Path in both modes (User and Admin) and found that my new path doesn't exist when I am under User, but I can see it when Powershell is as Administrator

How I can make my newly added variable visible running under User rather than Administrator?

UPDATE I ran 2 commands under User and the result is different. Why doesn't $env:Path display the same output as [System.Environment]::GetEnvironmentVariable('PATH', 'MACHINE') and why current PSSession doesn't see the path from the latter command?`

$env:Path

STEPS TO REPRODUCE

  1. Add environemt path variable [Environment]::SetEnvironmentVariable('PATH', ($env:Path + ';C:\Program Files\Foo'), 'MACHINE')
  2. Close the session
  3. Open a NEW ps session as user -> check $env:PATH -> C:\Program Files\Foo is not there
  4. Open a NEW ps session as admin -> check $env:PATH -> C:\Program Files\Foo is there


Solution 1:[1]

Unless I've missed something, I cannot reproduce your issue, here's example, I've just perfromed on a Test machine for you.

First I opened an elevated powershell.exe window, i.e. 'as administrator`:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\WINDOWS\system32> $Env:Path
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\Tester\AppData\Local\Microsoft\WindowsApps
PS C:\WINDOWS\system32> [Environment]::SetEnvironmentVariable('Path', ($Env:Path + ';C:\Program Files\Foo'), 'MACHINE')
PS C:\WINDOWS\system32> $Env:Path
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\Tester\AppData\Local\Microsoft\WindowsApps
PS C:\WINDOWS\system32> [Environment]::GetEnvironmentVariable('Path', 'MACHINE')
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\Tester\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Foo
PS C:\WINDOWS\system32>

Then I opened a new non elevated powershell.exe window:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\Tester> $Env:Path
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\Tester\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Foo;C:\Users\Tester\AppData\Local\Microsoft\WindowsApps;
PS C:\Users\Tester> [Environment]::GetEnvironmentVariable('Path', 'MACHINE')
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\Tester\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Foo
PS C:\Users\Tester>

As you can see C:\Program Files\Foo was shown in both example outputs.

Then I opened another new elevated powershell.exe window:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\WINDOWS\system32> $Env:Path
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\Tester\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Foo;
PS C:\WINDOWS\system32> [Environment]::GetEnvironmentVariable('Path', 'MACHINE')
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Users\Tester\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Foo
PS C:\WINDOWS\system32>

As you can see C:\Program Files\Foo was shown in both example outputs.

Solution 2:[2]

This issue suddenly appeared for me out of the blue and I was able to solve it for myself at least.

Warning: backup your PATH somewhere before running anything. There's a 1024ch limit so be careful.

Background

As a user (non-admin), your $Path is the equivalent of [System.Environment]::GetEnvironmentVariable('PATH', 'USER') while as admin your $Path is the equivalent of [System.Environment]::GetEnvironmentVariable('PATH', 'MACHINE'). There are probably many instances where you want these separated. In my case everything under my "MACHINE" $Path are things I'd want as a regular user, so I'll just show how to combine these paths so that no matter how you run powershell you'll have the same path.

Process

  1. Open cmd.exe as an administrator (there's probably a way to do this in powershell but this method seems so much easier and will apply to powershell fine)
  2. Add the combined paths to the user path:
setx path "%path%"

(within cmd %path% is a combination of both the user and machine paths)

  1. (Extra) Add the combined paths to the system path:
setx /M path "%path%"
  1. Restart powershell. The executables you expect should now be available as a user.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Vera