title: How to use Powershell to list duplicate files in a folder structure that exist in one of the folders
body: <p>I have a source tree, say c:\s, with many sub-folders.   One of the sub-folders is called "c:\s\Includes" which can contain one or more .cs files recursively.</p>
  
  <p>I want to make sure that none of the .cs files in the c:\s\Includes... path exist in any other folder under c:\s, recursively.</p>
  
  <p>I wrote the following PowerShell script which works, but I'm not sure if there's an easier way to do it.  I've had less than 24 hours experience with PowerShell so I have a feeling there's a better way.</p>
  
  <p>I can assume at least PowerShell 3 being used.</p>
  
  <p>I will accept any answer that improves my script, but I'll wait a few days before accepting the answer.  When I say "improve", I mean it makes it shorter, more elegant or with better performance.</p>
  
  <p>Any help from anyone would be greatly appreciated.</p>
  
  <p>The current code:</p>
  
  <pre><code>$excludeFolder = "Includes"
  
  $h = @{}
  foreach ($i in ls $pwd.path *.cs -r -file | ? DirectoryName -notlike ("*\" + $excludeFolder + "\*")) { $h[$i.Name]=$i.DirectoryName }
  ls ($pwd.path + "\" + $excludeFolder) *.cs -r -file | ? { $h.Contains($_.Name) } | Select @{Name="Duplicate";Expression={$h[$_.Name] + " has file with same name as " + $_.Fullname}}
  </code></pre>