Skip to content

Instantly share code, notes, and snippets.

@tebeco
Last active February 1, 2024 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tebeco/5c6cc0eee8c28fad3523008d58f83914 to your computer and use it in GitHub Desktop.
Save tebeco/5c6cc0eee8c28fad3523008d58f83914 to your computer and use it in GitHub Desktop.
fix dotnet path
$OldSysPath=[System.Environment]::GetEnvironmentVariable('PATH', [System.EnvironmentVariableTarget]::Machine); `
$Hasx86=($OldSysPath.Split(';') | ? { $_.StartsWith('C:\Program Files (x86)\dotnet\')}).Count -gt 0; `
if ($Hasx86) {
Write-Host "**********************************************************************"; `
Write-Host "If you're seing this message your SYS PATH is improperly set" -ForegroundColor Yellow; `
$NewSystemPath=$OldSysPath.Replace('C:\Program Files (x86)\dotnet\', 'C:\Program Files\dotnet\'); `
Write-Host "**********************************************************************"; `
Write-Host "Your Old PATH was:" -ForegroundColor Green; `
Write-Host "$($OldSysPath)"; `
Write-Host "**********************************************************************"; `
Write-Host "Your New PATH will be:" -ForegroundColor Green; `
Write-Host "$($NewSystemPath)"; `
Write-Host "Press enter to continue (Ctrl+C to ABORT)" -ForegroundColor Red -NoNewLine; Read-Host; `
Write-Host "**********************************************************************"; `
[System.Environment]::SetEnvironmentVariable('PATH', $NewSystemPath, [System.EnvironmentVariableTarget]::Machine) `
}
else {
Write-Host "**********************************************************************"; `
Write-Host "Everything seems fine as we could not find a match in PATH for 'C:\Program Files (x86)\dotnet\' ... which is fine" -ForegroundColor Green `
Write-Host "**********************************************************************";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment