title: Exclude sub-directories from Compress-Archive Powershell Cmd
body: <p>I apologize in advance if this question seems odd, this is my first time trying to use powershell for anything like this.</p>
  
  <p>I have a directory structure similar to the following:</p>
  
  <pre><code>DIR1/
      bin/
      obj/
      d1-file1
      d1-file2 
  DIR2/
      bin/
      obj/
      d2-file1
      d2-file2
  DIR3/
      bin/
      obj/
      d3-file1
      d3-file2
  </code></pre>
  
  <p>I am trying to compress this list of directories with a set of top-level and sub-level exclusions. For example, I'd like to exclude a specific top-level directory (eg. DIR2) while also excluding specific sub-directories from the final result set (eg. bin, obj).</p>
  
  <p>I have tried a few different approaches but unfortunately, when I iterate through the sub-directories the compress-archive command will zip up the sub-level items without retaining the top level directory structure. I'd like to retain the top-level directory structure in the archive while also excluding the specified sub-directories.</p>
  
  <pre><code>$entries = New-Object System.Collections.Generic.List[System.Object] 
  
  # Get initial directory listing
  $dirlist = Get-ChildItem $solutionFileLocation -ad -Exclude "DIR2" | ForEach-Object { $_.FullName }
  
  # Exclude bin and obj directories and add entry path to our zip entry list
  foreach ($dir in $dirlist)
  {
      $sub = Get-ChildItem $dir -Exclude "bin", "obj" | ForEach-Object { $_.FullName }
  
      foreach ($itm in $sub)
      {
          $entries.Add($itm)
      }
  }
  
  Compress-Archive -LiteralPath $entries -CompressionLevel Optimal -DestinationPath "C:\Filename01212019.zip"
  </code></pre>
  
  <p>The result is an archive containing the following:</p>
  
  <pre><code>d1-file1
  d1-file2
  d3-file1
  d3-file2
  </code></pre>
  
  <p>Instead of the desired result:</p>
  
  <pre><code>DIR1/
      d1-file1
      d1-file2 
  DIR3/
      d3-file1
      d3-file2
  </code></pre>