How to zip/unzip files in Powershell?

DotNetZip will allow you to do this from PowerShell. It is not a one-liner, but the library will allow you to write the PowerShell script you need.

You can also use the COM interface, see Compress Files with Windows PowerShell then package a Windows Vista Sidebar Gadget.

Googling "zip powershell" or "unzip powershell" might also turn up useful results.


This is how you can do it purely from Powershell without any external tools. This unzips a file called test.zip onto the current working directory:

$shell_app=new-object -com shell.application
$filename = "test.zip"
$zip_file = $shell_app.namespace((Get-Location).Path + "\$filename")
$destination = $shell_app.namespace((Get-Location).Path)
$destination.Copyhere($zip_file.items())

Now in .NET Framework 4.5, there is a ZipFile class that you can use like this:

[System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
[System.IO.Compression.ZipFile]::ExtractToDirectory($sourceFile, $targetFolder)