Created
September 15, 2010 18:06
-
-
Save ajmath/581162 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### findDuplicatesInPath.ps1 | |
### Andrew Matheny - [email protected] | |
### | |
### 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