Windows 11 - Duplicate values in environment path

Byron Sisson 6 Reputation points
2022-11-09T20:21:19.49+00:00

I recently upgrade to Windows 11 from 10, but I don't know if that is related to the current. I started having the problem of PowerShell not finding programs when not supplied with the full path. For instance, ping works with no path from a CMD prompt, but does not from a PowerShell prompt. I get the error:

ping: The term 'ping' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

That sent me down the path of looking at the environment PATH when I discovered duplications. I've seen posts about cleaning duplicates out by editing through the GUI, or directly in the registry, but neither of those paths display the duplicates. The output from a CMD prompt from ECHO %PATH% follows. I split the string across multiple lines after the ; separator to make it easier to read. Where a line begins with a semicolon it's because there were two semicolons in the string.

C:\WINDOWS\System32;
D:\Program Files\Python\Python39\Scripts;
C:\Windows\System32\OpenSSH;
C:\Program Files\dotnet\;
;D:\Program Files\Python\Python39\Scripts;
C:\Windows\System32\OpenSSH;
C:\Program Files\dotnet\;
;D:\Program Files\Python\Python39\Scripts;
C:\Windows\System32\OpenSSH;
C:\Program Files\dotnet\;
C:\Users\byron\AppData\Local\Microsoft\WindowsApps;
C:\Program Files\Azure Data Studio\bin;
D:\Programs\Microsoft VS Code\bin;
C:\Program Files\JetBrains\PyCharm Community Edition 2022.2.3\bin;;

As you can see, there are path duplicated.

The path values from the registry are:

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
%PATH%;D:\Program Files\Python\Python39\Scripts;C:\Windows\System32\OpenSSH;C:\Program Files\dotnet\;

Computer\HKEY_CURRENT_USER\Environment
%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Azure Data Studio\bin;D:\Programs\Microsoft VS Code\bin;%PyCharm Community Edition%;

I checked the path values through the Windows GUI as a sanity check and they correspond with the values from the registry as expected.

From PowerShell, $env:Path results in:

C:\Program Files\PowerShell\7;%PATH%;D:\Program Files\Python\Python39\Scripts;C:\Windows\System32\OpenSSH;C:\Program Files\dotnet\;C:\Users\byron\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Azure Data Studio\bin;D:\Programs\Microsoft VS Code\bin;C:\Program Files\JetBrains\PyCharm Community Edition 2022.2.3\bin;;

Is there somewhere else the paths can get pulled from, or is this a known issue? I'd also like to know why PowerShell is displaying a different path, but I have not gone far looking for that yet.

Windows for business Windows Client for IT Pros User experience Other
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. KurtBMayer 841 Reputation points
    2022-11-09T22:46:31.937+00:00

    @Byron Sisson

    Try uninstalling/reinstalling the latest PWSH 7.3 version.

    PowerShell

    Naturally, you can't remove 5.1.

    Please upvote and accept this thread as answered if it's helpful, thanks!

    1 person found this answer helpful.

  2. Luc Van der Veken 15 Reputation points
    2023-08-04T07:42:16.57+00:00

    I noticed in my Win11 upgraded from win10, that some system (OS) paths were included twice in the path, once "plain" and once through variable expansion.For example the windows directory was included as "C:\Windows", and a second time as "%systemroot%"; the system32 directory as "C:\Windows\System32" and as "%systemroot%\system32", the wbem directory as "C:\Windows\System32\wbem" and as "%systemroot%\system32\wbem".

    All of them appeared twice in the cmd.exe path.

    I guess this could be caused by different default ways to include them in 10 versus 11, while upgrading from 10 to 11 could be adding the new "default" values without deleting the old.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.