Oddly enough, the correct logic already appears in the file, but its commented
#$envPath = [Environment]::GetEnvironmentVariable('Path', $pathType)
If I ask to install a new PATH to SYSTEM, the local environment PATH (which is the combo of SYSTEM + USER + PROCESS) should not be considered.
If I need something to be accessible to the SYSTEM (for instance to a service process), then this check could prevent a good path from being registered for the SYSTEM.
I assume this is an attempt to prevent adding a PATH to multiple spots to save PATH space.. but it's assuming a little too much IMHO.
I think that script could use a bit of a refactor... there's a lot of unnecessary futzing around with ;
Just -split ';' into an array, add to the array if the -contains fails ... then -join ';'
Agreed on refactoring - need to get in a PR that might fix this prior to a refactor though.
Is this still relevant?