How to unzip a file in PowerShell

Unzipping a file on your PowerShell command line may come in handy sometimes, even on your Windows 10 or Windows 8.1 workstation. All that is required is PowerShell and the .NET 4.5 Framework.

The System.IO.Compression namespace contains the following types for compressing and decompressing files and streams. You can also use these types to read and modify the contents of a compressed zip archive file.

A simple way of using ExtractToDirectory from System.IO.Compression.ZipFile:

Add-Type -AssemblyName System.IO.Compression.FileSystem
function unzip {
    param( [string]$ziparchive, [string]$extractpath )
    [System.IO.Compression.ZipFile]::ExtractToDirectory( $ziparchive, $extractpath )

unzip "D:\" "C:\temp"

How to: Compress and Extract Files

And in PowerShell 5.0, there is an Expand-Archive command built in:

Expand-Archive D:\ -DestinationPath C:\temp

To compress, you can use Compress-Archive.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Hi! Join the discussion, leave a reply!