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.

Use the automatic $PSVersionTable variable, and check the PSVersion property, to get the PowerShell version. For example: $PSVersionTable.PSVersion


Want to say thanks?

If I’ve helped you out and you want to thank me, why not buy me a coffee?

If I’ve helped you out and you want to thank me, why not buy me a coffee?

Thank you for your support. ♥

Categories: Windows 10

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, WordPress, websites & optimization. Want to support me and donate? Use this link: https://paypal.me/jreilink.

Leave a Reply

Your email address will not be published. Required fields are marked *

20 queries, 0.195 seconds running PHP version 7.3.2