Skip to main content

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:\file.zip" "C:\temp"

How to: Compress and Extract Files

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

Expand-Archive D:\file.zip -DestinationPath C:\temp

To compress, you can use Compress-Archive.

I thought you might find this interesting:   Generate pseudo-random passwords with OpenSSL

Jan Reilink

My name is Jan. I am not a hacker, coder, developer, programmer or guru. I am merely a system administrator, doing my daily thing at Vevida in the Netherlands. With over 15 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, websites & optimization.

Hi! Join the discussion, leave a reply!