Create Zip files within Powershell

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


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 )
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)


$zipfile = new-object Ionic.Utils.Zip.ZipFile(“”);

ZipUp-Files “DotNetZip”



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  to get DotNetZip.

Comments (1)

  1. Last year, I wrote about the idea of PowerShell CmdLets for WebSphere MQ. PowerShell is a beautiful scripting