Blogs:

Removing Duplicate Entries from %PATH%

Mark

June 30, 2012 / 2 Comments

As developers, we frequently end up with duplicate entries in our path. From the command line you can clean up your path using pathman.exe. Here’s a PowerShell Script to find the duplicates and remove them using Pathman.exe:

$extraPath=(($path.Split("`;") | group | ?{$_.Count -gt 1}).Values | %{$_[0]}
pathman.exe /ru $extrapath

Disclaimer: Works for us.

AUTHOR: CATEGORY: PowerShell, Windows

2 Responses to “Removing Duplicate Entries from %PATH%”

  1. Thomas Schweikle says:

    Can’t work. At least one closing “)” is missing.

  2. Michael Sinz says:

    Here is a “cute” way to do it in plain CMD shell script:

    I called the script “CleanupPath.cmd” and you just run it and your path duplicates will be removed without changing the order of the path.

    @setlocal EnableExtensions EnableDelayedExpansion
    @set _PATH_=
    @for %%a in (“%PATH:;=” “%”) do @if not “%%~a” == “” (
    @if “!_PATH_!” == “” @set “_PATH_=;%%~a;”
    @set “_T_=!_PATH_:;%%~a;=x!”
    @if “!_T_!” == “!_PATH_!” @set “_PATH_=!_PATH_!%%~a;”
    )
    @endlocal && @set “PATH=%_PATH_:~1,-1%

Leave a Reply


Contact Us
Email: info@IntelliTect.com
Phone: (509) 315-3400




Testimonials

I would not hesitate to use Mark and his team again.  He and his team have an excellent grasp of current technology  and software development methodologies as well as insight into how to appropriately apply them.
- Brahma Holding, La Jolla, CA
CONTACT US: (509) 315-3400 | Info@IntelliTect.com | Jobs | Site Map