Update PATH envrionment variable for package manager executable on Windows by daxian-dbw · Pull Request #25847 · PowerShell/PowerShell

@daxian-dbw daxian-dbw added the CL-General

Indicates that a PR should be marked as a general cmdlet change in the Change Log

label

Aug 11, 2025

iSazonov

iSazonov

iSazonov

theJasonHelmick

adityapatwardhan

@daxian-dbw

TravisEz13

@daxian-dbw

TravisEz13

@daxian-dbw

iSazonov

TravisEz13

SIRMARGIN pushed a commit to SIRMARGIN/PowerShell that referenced this pull request

Dec 12, 2025
…ndows (PowerShell#25847)

Implementation for PowerShell/PowerShell-RFC#391. A few implementation decisions:

1. Check the package manager list only once per process (**same as CMD**). So, changing the package manager list in registry doesn't affect a PowerShell session that is already running.

2. When detecting user/system PATH value changes, only check new items PREPENDED or APPENDED to the original string (**same as CMD**). The detection is made simple, which is not intended to detect complex changes to the user/system PATH.

3. The PATH update feature is disabled when the `Environment` provider is not available, or when the current session is restricted.
    - Both `Environment` provider and `IsSessionRestricted` are checked only once per PowerShell session.
    - Use `ConditionalWeakTable` to cache whether the feature is enabled or not for a given session.
    - We cannot use `thread-static` variable for the caching because it's possible for Runspace to reuse threads.