Create Zip files within Powershell

You can use DotNetZip library from within Powershell.  It's pretty simple, fast, easy.

example:

 function ZipUp-Files ( $directory )
{

  $children = get-childitem -path $directory
  foreach ($o in $children) 
  {
    if ($o.Name -ne "TestResults" -and 
        $o.Name -ne "obj" -and 
        $o.Name -ne "bin" -and 
        $o.Name -ne "tfs" -and 
        $o.Name -ne "notused" -and 
        $o.Name -ne "Release")
    {
      if ($o.PSIsContainer)
      {
        ZipUp-Files ( $o.FullName )
      }
      else 
      {
        if ($o.Name -ne ".tfs-ignore" -and
           !$o.Name.EndsWith(".cache") -and
           !$o.Name.EndsWith(".zip") )
        {
          Write-output $o.FullName
          $e= $zipfile.AddFile($o.FullName)
        }
      }
    }
  }
}


[System.Reflection.Assembly]::LoadFrom("c:\\\bin\\Ionic.Utils.Zip.dll");

$zipfile =  new-object Ionic.Utils.Zip.ZipFile("zipsrc.zip");

ZipUp-Files "DotNetZip"

$zipfile.Save()

 

The example above shows how to create a zip.  I use it to zip up a directory containing source files, and I leave out any unwanted files or directories. Of course you can also extract a zip, view a zip, Update a zip, and so on.   Anything you can do in the DotNetZip library, you can do in Powershell.

Visit https://www.codeplex.com/DotNetZip  to get DotNetZip.