Esta não é uma resposta real (muito longa e complexa demais para um comentário). eu vou deletar se for falso.
Use o seguinte script ingênuo para verificar se sua configuração path
é formalmente válida:
Function myTest-Path {
Param( [Parameter(Mandatory=$true)] [string] $PathString )
if ( $PathString -match '%' ) { $PathString = (. cmd /c "echo($PathString")}
if ( Test-Path -Path $PathString -IsValid) {
[string] (Test-Path (Join-Path -ChildPath '' -Path $PathString))
} else { '!wrong' }
}
### Windows path validity check ###
Write-Host '$env:Path splitted' -ForegroundColor Yellow
$aux = $env:Path
$aux -split ";" | ForEach-Object {'{0,6} "{1}"' -f (myTest-Path $_), $_}
Write-Host 'HKCU:\Environment\ Path splitted' -ForegroundColor Yellow
$aux = ([Microsoft.Win32.Registry]::CurrentUser.
OpenSubKey("environment")).
GetValue("Path",$False,
[Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
$aux -split ";" | ForEach-Object {'{0,6} "{1}"' -f (myTest-Path $_), $_}
Write-Host 'HKLM:\SYSTEM\…\Environment\ Path splitted' -ForegroundColor Yellow
$aux = ([Microsoft.Win32.Registry]::LocalMachine.
OpenSubKey("SYSTEM\CurrentControlSet\Control\Session Manager\Environment")).
GetValue("Path",$False,
[Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
$aux -split ";" | ForEach-Object {'{0,6} "{1}"' -f (myTest-Path $_), $_}
Write-Host '$env:Path duplicities' -ForegroundColor Yellow
$auxArr = $env:Path -split ";"
for ($i = 0; $i -le $auxArr.Count; $i++) {
for ($j = $i+1; $j -le $auxArr.Count -1; $j++) {
try {
if ( (Join-Path -ChildPath '' -Path $auxArr[$j] -ErrorAction Stop) -eq
(Join-Path -ChildPath '' -Path $auxArr[$i] -ErrorAction Stop) ) {
'{0,4} {1,4} "{2}"' -f $i, $j, $auxArr[$i]
}
} catch {
### Write-Host "$i $j invalid folder name in '$env:Path" -ForegroundColor Red
}
}
}