Sysadmins of the North
Share now!





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 workstation. Use Expand-Archive for this, and all that is required is PowerShell 5.0+, or the .NET 4.5+ Framework to use System.IO.Compression.ZipFile.

Unzip a file in PowerShell 5.0, there is an Expand-Archive cmdlet built in:

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

To compress files with PowerShell, you can use Compress-Archive.

Use the automatic $PSVersionTable variable, and check the PSVersion property, to get the PowerShell version. For example: $PSVersionTable.PSVersion. This should inform your whether Expand-Archive is available.

If you want a wrapper to unzip files with .NET Framework, then you can use the the System.IO.Compression namespace. This namespace contains classes that provide basic compression and decompression services for streams. You can also use these classes 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


buy me a coffee
Buy Me A Coffee

About the Author 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.

follow me on:


Thank you!

Leave a Comment:

1 comment
Add Your Reply
Skip to content Q xeB Goaa dX