INTELLIGENT.TECHNICAL.ARCHITECTURE.TRAINING

 
 
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

Comments

  • Thomas Schweikle says:

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

  • 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

    Your Name:
    Your Email Adress:
    Your comment:

     

    IntelliTect Corporation
    3024 S. Bannen Ct.
    Spokane Valley, WA  99037

    Phone: (509) 315-3400
    Email: info@intelliTect.com

      COPYRIGHT © 2006-2012 INTELLITECT. ALL RIGHTS RESERVED.