Hash Tables are a great way to find duplicates. Simply use the Hash Table as lookup to see if the file (or element) was already added to the Hash Table. The following script would find all files and folder with same name in the current folder, the windows folder and its system32 subfolder.
function Find-Duplicates
{
$Input | ForEach-Object {
if ($lookup.ContainsKey($_.Name.toLower()))
{
"$($_.FullName) is a duplicate in $($lookup.$($_.Name.toLower()))"
} else
{
$lookup.Add($_.Name.toLower(), $_.FullName)
}
}
}
$lookup = @{}
dir | Find-Duplicates
dir $env:windir | Find-Duplicates
dir $env:windirsystem32 | Find-Duplicates