Appending to $env:Path and saving to User PATH copies Machine PATH in
env paths · case
Affectspowershell 51, pwsh 7, windows
Fails assilent
Mechanismregistry env snapshot
Safe fixscope read path
Symptom
Section titled “Symptom”After an installer “adds one directory to PATH”, the user’s User PATH suddenly contains the entire system PATH — duplicated. Future Machine PATH changes get shadowed by the stale copy, and the PATH grows every time the pattern runs.
# The innocent-looking pattern:[Environment]::SetEnvironmentVariable('Path', $env:Path + ';C:\tools', 'User')# $env:Path is the MERGED Machine+User view — you just wrote all of it into User.$env:Path is the process-level merge of Machine and User PATH. Using it as
the base for a User-scope write permanently copies every Machine entry into the
User value. The corruption is silent and compounds across installers.
Workaround
Section titled “Workaround”$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')if ($userPath -notlike "*C:\tools*") { [Environment]::SetEnvironmentVariable('Path', "$userPath;C:\tools", 'User')}Read the specific scope, append only the missing entry. The referenced fix replaced the merged-view guidance with exactly this scope-read pattern.