Skip to content

Instantly share code, notes, and snippets.

@ajmath
Created September 15, 2010 18:06
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 ajmath/581162 to your computer and use it in GitHub Desktop.
Save ajmath/581162 to your computer and use it in GitHub Desktop.
### findDuplicatesInPath.ps1
### Andrew Matheny - andrew.j.matheny@gmail.com
###
### Powershell script that examines all exes in directories in the Path environment
### variable and prints a listing of duplicates and their respective paths.
$dirs = $Env:PATH.Split(';');
$exehash = @{};
foreach($d in $dirs)
{
$d = $(New-Object -ComObject wscript.shell).ExpandEnvironmentStrings($d);
if(![System.IO.Directory]::Exists($d)) { continue;}
$files = Get-ChildItem -name $d | FindStr /e \.exe;
foreach($file in $files)
{
$exehash[$file] = $exehash[$file] + ";" + $d + "\" + $file;
}
}
foreach($key in $exehash.Keys)
{
$split = $exehash[$key].Split(';');
if($split.length -gt 2)
{
echo $key;
foreach($match in $split)
{
echo $(" " + $match);
}
echo "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment