Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-2044) Fix for changing $env:Temp #2154

Merged
merged 3 commits into from
May 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,34 @@ None
}

if ($refreshEnv) {
Write-Output "Refreshing environment variables from the registry for powershell.exe. Please wait..."
Write-Output 'Refreshing environment variables from the registry for powershell.exe. Please wait...'
} else {
Write-Verbose "Refreshing environment variables from the registry."
Write-Verbose 'Refreshing environment variables from the registry.'
}

$userName = $env:USERNAME
$architecture = $env:PROCESSOR_ARCHITECTURE
$psModulePath = $env:PSModulePath

#ordering is important here, $user comes after so we can override $machine
'Process', 'Machine', 'User' |
% {
$scope = $_
Get-EnvironmentVariableNames -Scope $scope |
% {
Set-Item "Env:$($_)" -Value (Get-EnvironmentVariable -Scope $scope -Name $_)
#ordering is important here, $user should override $machine...
$ScopeList = 'Process', 'Machine'
if ($userName -notin 'SYSTEM', "${env:COMPUTERNAME}`$") {
# but only if not running as the SYSTEM/machine in which case user can be ignored.
$ScopeList += 'User'
}
foreach ($Scope in $ScopeList) {
Get-EnvironmentVariableNames -Scope $Scope |
ForEach-Object {
Set-Item "Env:$_" -Value (Get-EnvironmentVariable -Scope $Scope -Name $_)
}
}
}

#Path gets special treatment b/c it munges the two together
$paths = 'Machine', 'User' |
% {
ForEach-Object {
(Get-EnvironmentVariable -Name 'PATH' -Scope $_) -split ';'
} |
Select -Unique
Select-Object -Unique
$Env:PATH = $paths -join ';'

# PSModulePath is almost always updated by process, so we want to preserve it.
Expand All @@ -91,7 +94,7 @@ None
if ($architecture) { $env:PROCESSOR_ARCHITECTURE = $architecture; }

if ($refreshEnv) {
Write-Output "Finished"
Write-Output 'Finished'
}
}

Expand Down