title: Powershell system.io.compression zipping files and/or Folders
body: <p>Im producing some automated tasks at work where i need to zip certain files and/or folders.
  What im trying to do is getting zip the text files  in folder 1 which contains 4 txt files.</p>
  
  <p>Executing this command gives an error but still zips the txt files :</p>
  
  <pre><code>Exception calling "CreateFromDirectory" with "4" argument(s): "The directory name is invalid.
  "
  At line:15 char:13
  +             [System.IO.Compression.ZipFile]::CreateFromDirectory($Source, "$Sour ...
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
  </code></pre>
  
  <p>What i got now is:</p>
  
  <pre><code>[Reflection.Assembly]::LoadWithPartialName( "System.IO.Compression.FileSystem" )
  $includeBaseDirectory = $false
  $compressionLevel= [System.IO.Compression.CompressionLevel]::Optimal
  
  $source = "C:\folder1\*"
  Get-ChildItem $source -include *.txt  |
  Foreach {
          $Source = $_.fullName
          [System.IO.Compression.ZipFile]::CreateFromDirectory    ($Source, "$Source.zip",$compressionLevel, $includebasedirectory)
          }
  </code></pre>
  
  <p>Also if i want to zip the folders  inside folder1 i use -directory switch instead of include. 
  that doesnt produce any error messages. 
  any suggestions?</p>