Getting Zippy with PowerShell v5

*Warning. This article was written using the September 2014 PowerShell v5 Preview*

PowerShellZip01

 

(OK, I was really looking for an excuse to use the below picture in a blog post)

Zippy

 

One of the most popular and long standing requests for PowerShell is native support for working with Zip files. With PowerShell v5 we get two new cmdlets Compress-Archive  and and Expand-Archive. Here’s a couple of examples of how they work.

Compress-Archive

1) Create a Zip file

C:\Test contains a number of text files. We want to zip them up into one convenient file.

PowerShellZip02

 

Compress-Archive -Path C:\Test\* -DestinationPath C:\Zip\Test.zip -CompressionLevel Optimal

and now we have the zip file:

Note: as of this release there are three Compression Levels, the default of which is Optimal.

 

PowerShellZip04

PowerShellZip05

2) Update a Zip file

Now we add an extra file to C:\Test and want to update the zip file with this new file

 

PowerShellZip06

Compress-Archive -Path C:\Test\* -DestinationPath C:\Zip\Test.zip -Update

Here’s the new file, now contained in the zip file:

PowerShellZip07

Expand-Archive

3) Expand a Zip file

Now we want to expand a zip file. Let’s use the one we just created and expand it to a different folder C:\Expand.

Expand-Archive -Path C:\Zip\Test.zip -DestinationPath C:\Expand

Here are the files:

PowerShellZip08

All pretty straightforward, but it’s great to have this simple functionality finally native 🙂