title: Powershell Script to find duplicate files
body: <p>I found a PowerShell script on TechNet to help locate duplicate files in folders. However, when I run it, I am getting an error on what appears to be every folder\file. Not sure what switch is supposed to be used in this.</p>
  
  <pre><code>$Path = '\\servername\Share\Folders' #define path to folders to find duplicate files
  $Files=gci -File -Recurse -path $Path | Select-Object -property FullName,Length
  $Count=1
  $TotalFiles=$Files.Count
  $MatchedSourceFiles=@()
  ForEach ($SourceFile in $Files)
  {
    Write-Progress -Activity "Processing Files" -status "Processing File $Count / $TotalFiles" -PercentComplete ($Count / $TotalFiles * 100)
    $MatchingFiles=@()
    $MatchingFiles=$Files |Where-Object {$_.Length -eq $SourceFile.Length}
    Foreach ($TargetFile in $MatchingFiles)
    {
      if (($SourceFile.FullName -ne $TargetFile.FullName) -and !(($MatchedSourceFiles |
        Select-Object -ExpandProperty File) -contains $TargetFile.FullName))
      {
        Write-Verbose "Matching $($SourceFile.FullName) and $($TargetFile.FullName)"
        Write-Verbose "File sizes match."
        if ((fc.exe /A $SourceFile.FullName $TargetFile.FullName) -contains "FC: no differences encountered")
        {
          Write-Verbose "Match found."
          $MatchingFiles+=$TargetFile.FullName
        }
      }
    }
    if ($MatchingFiles.Count -gt 0)
    {
      $NewObject=[pscustomobject][ordered]@{
        File=$SourceFile.FullName
        MatchingFiles=$MatchingFiles
      }
      $MatchedSourceFiles+=$NewObject
    }
    $Count+=1
  }
  $MatchedSourceFiles
  </code></pre>
  
  <p>Errors</p>
  
  <p>FC: Insufficient number of file specifications
  fc.exe : FC: Invalid Switch
  At line:18 char:12</p>
  
  <p>gci : Could not find a part of the path
  At line:2 char:8</p>
  
  <p>fc.exe : FC: Invalid Switch
  At line:18 char:12</p>