Created
December 28, 2014 17:15
-
-
Save bill-long/230830312b70742321e0 to your computer and use it in GitHub Desktop.
Refreshes the path variable in a Powershell session. Taken from http://stackoverflow.com/questions/14381650/how-to-update-windows-powershell-session-environment-variables-from-registry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach($level in "Machine","User") { | |
[Environment]::GetEnvironmentVariables($level).GetEnumerator() | % { | |
# For Path variables, append the new values, if they're not already in there | |
if($_.Name -match 'Path$') { | |
$_.Value = ($((Get-Content "Env:$($_.Name)") + ";$($_.Value)") -split ';' | Select -unique) -join ';' | |
} | |
$_ | |
} | Set-Content -Path { "Env:$($_.Name)" } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. This helped me resolve an issue where I have to install an MSI inside an AppVeyor build and therefore had to refresh the path.