Hey Y’all,
I found this PowerShell script as an answer to a question on StackOverflow and thought it would be useful to our readers.
The Path statement gets polluted over time by directories that no longer exist and duplicates because some install program just added directories that it needed w/o checking to see if they were already there.
This little script will output a color coded list of all the Directories in the path environment variable with the active ones in green and the dead ones in red. Don’t forget to check the green ones for duplicates especially those that start with C:\Windows and %systemroot% as system root will evaluate to C:\Windows!
Author: Panomosh @ StackOverFlow.com
Clear-Host foreach($path in ((get-childitem -path env:\path | Select -exp Value).split(";"))){ if($Path -ne "") { If (Test-Path $path){ Write-host "True - $path" -ForegroundColor Green } else {Write-host "False - $path" -ForegroundColor Red } } #End Select } #End For-Each
To edit your path use:
- Control Panel
- System
- Advanced system settings
- Environment Variables…
- System variables (bottom Window) then select Path and Edit.