Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$variables =
[Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine) -split ';' |
foreach { $_.Trim().TrimEnd('\\') } |
group |
select -ExpandProperty Name |
where { -not [string]::IsNullOrWhitespace($_) }
$path = $variables -join ';'
[Environment]::SetEnvironmentVariable("PATH", $path, [System.EnvironmentVariableTarget]::Machine)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment