Skip to content

Appending to $env:Path and saving to User PATH copies Machine PATH in

env paths · case

bothsilentscriptfirst-partyrepro: verifiedregistry-env-snapshot
Affectspowershell 51, pwsh 7, windows
Fails assilent
Mechanismregistry env snapshot
Safe fixscope read path

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.

Terminal window
# 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.

Terminal window
$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.