Powershell – How to Zip and UnZip with a Script

[wpfilebase tag=file path='01/SharpZipLib_0860_Bin.zip']

Here are some easy-to-use functions for zipping up a directory and unzipping using Powershell. The functions use the opensource SharpZipLib library, a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform.

So you'll need to download this and reference the SharpZipLib assembly in the appropriate place in the functions below.

Usage

function ZipFiles( $sourcePath, $zipFilename )
{
# Reference the SharpZipLib assembly here

[System.Reflection.Assembly]::LoadFrom( "C:\ICSharpCode.SharpZipLib.dll" )
$zip = New-Object ICSharpCode.SharpZipLib.Zip.FastZip
$zip.CreateZip($zipFilename, $sourcePath, $true, "")
}

function UnzipFiles( $zipFilename, $destinationPath )

{

# Reference the SharpZipLib assembly here

[System.Reflection.Assembly]::LoadFrom( "C:\ICSharpCode.SharpZipLib.dll" )
$zip = New-Object ICSharpCode.SharpZipLib.Zip.FastZip

$zip.ExtractZip($zipFilename, $destinationPath, "")

}
SOURCE

LINK

LANGUAGE
ENGLISH