Apologies. 'changePath' is supposed to be a function definition I don't understand why all the formatting got removed. Let me try again...
function changePath ($action, $addendum) {
$regLocation =
"Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment"
$path = (Get-ItemProperty -Path $regLocation -Name PATH).path
# Add an item to PATH
if ($action -eq "add") {
$path = "$path;$addendum"
Set-ItemProperty -Path $regLocation -Name PATH -Value $path
}
# Remove an item from PATH
if ($action -eq "remove") {
$path = ($path.Split(';') | Where-Object { $_ -ne "$addendum" }) -join ';'
Set-ItemProperty -Path $regLocation -Name PATH -Value $path
}
}