Update-Path.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
function Update-Path { $configuredPaths = [string[]] (& { foreach($path in & { (Get-ItemProperty 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment').Path; (Get-ItemProperty 'HKCU:\Environment').Path; }) { if($path) { $path.Split(';') | % { if($_) { $_ } } } } }) $currentPaths = $env:Path.Split(';') $newPaths = [string[]] $configuredPaths | ? { -not ($currentPaths -contains $_) } foreach($path in $newPaths) { Write-Warning "Adding $path will be added to PATH." $env:Path = $env:Path + ';' + $path } } |