How to create a zip archive with PowerShell?

Valentin Vasilyev picture Valentin Vasilyev · Jul 20, 2009 · Viewed 312.9k times · Source

Is it possible to create a zip archive using PowerShell?

Answer

petrsnd picture petrsnd · Nov 9, 2012

A pure PowerShell alternative that works with PowerShell 3 and .NET 4.5 (if you can use it):

function ZipFiles( $zipfilename, $sourcedir )
{
   Add-Type -Assembly System.IO.Compression.FileSystem
   $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal
   [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir,
        $zipfilename, $compressionLevel, $false)
}

Just pass in the full path to the zip archive you would like to create and the full path to the directory containing the files you would like to zip.