title: PowerShell - Find duplicate files and ignore multiple files in the same compressed file
body: <p>I got this script and modified it a bit (to avoid extract the same file to one temp file).
  I have two issues:</p>
  <ol>
  <li>When the script founds duplication, the SourchArchive always shows one file (instead of 2 that holds the same file inside)</li>
  <li>When a compressed file holds more than 1 same file in a different subfolder (in the same zip) the script return that there is duplication and its not good for me. If the compressed file has 3 files that are the same it should combined to 1 file and then compering it to another compressed file</li>
  </ol>
  <p><strong>Update:</strong></p>
  <p>The main goal is to compare between compressed files in order to find duplicate files inside the compressed files. The compressed files can be cab or zip (The zip could contains dlls, xml, msi and more. sometimes it contains also a vip files (vip is a compressed file that also contains files like dll))
  After compering each compressed file in another the output should be the compressed files that holds the same files inside
  It will be great to separate between the result with  ----------</p>
  <p>this should be as part of a bigger script that should stop if there are duplicate files in more than 1 compressed file so only if $MatchedSourceFiles has result the script will stop otherwise should continue. I hope its clear now</p>
  <pre><code>Example:
  test1.zip contains temp.xml 
  test2.zip contains temp.xml
  
  The output should be:
  SourceArchive       DuplicateFile
  test1.zip           temp.xml
  test2.zip           temp.xml
  ------------------------------
  The next duplication files 
  ------------------------------
  
  Example 2: (multiple identical files in the same compressed file)
  test1.zip contains 2 subfolders
  test1.zip contains temp.xml under subfolder1 and also temp.xml under subfolder2 
  
  The result should be none
  SourceArchive       DuplicateFile
  
  Example 3:
  test1.zip same as in example 2 
  test3.zip contains temp.xml
  
  The result should be:
  
  SourceArchive       DuplicateFile
      test1.zip           temp.xml
      test3.zip           temp.xml
      ------------------------------
      The next duplication files
      ------------------------------
      The next duplication files
      ------------------------------
  </code></pre>
  <p>Add-Type -AssemblyName System.IO.Compression.FileSystem</p>
  <pre><code>$tempFolder = Join-Path -Path ([IO.Path]::GetTempPath()) -ChildPath (New-GUID).Guid
  $compressedfiles = Get-ChildItem -Path 'C:\Intel' -Include '*.zip', '*.CAB' -File -Recurse
  
  $MatchedSourceFiles = foreach ($file in $compressedfiles) {
      switch ($file.Extension) {
          '.zip' {
              $t = $tempFolder + &quot;\&quot; + $file.Name
              # the destination folder should NOT already exist here
              $null = [System.IO.Compression.ZipFile]::ExtractToDirectory($file.FullName, $t )
              try {
                  Get-ChildItem -Path $tempFolder -Filter '*.vip' -File -Recurse | ForEach-Object {
                      $null = [System.IO.Compression.ZipFile]::ExtractToDirectory($_.FullName, $t)
                  }
              }
              catch {}
          }
          '.cab' {
              # the destination folder MUST exist for expanding .cab files
              $null = New-Item -Path $tempFolder -ItemType Directory -Force
              expand.exe $file.FullName -F:* $tempFolder &gt; $null
          }
      }
      # now see if there are files with duplicate names
      Get-ChildItem -Path $tempFolder -File -Recurse -Exclude vip.manifest, filesSources.txt, *.vip | Group-Object Name | 
      Where-Object { $_.Count -gt 1 } | ForEach-Object { 
          foreach ($item in $_.Group) {
              # output objects to be collected in $MatchedSourceFiles
              [PsCustomObject]@{
                  SourceArchive = $file.FullName
                  DuplicateFile = '.{0}' -f $item.FullName.Substring($tempFolder.Length)  # relative path
              }
          }
      }
  }
  
  # display on screen
  $MatchedSourceFiles
  $tempFolder | Remove-Item -Force -Recurse
  </code></pre>