Advertisement

Compress To ZIP and Extract From ZIP Using PowerShell

PowerShell is an advanced form of command prompt. It is extended with a huge set of ready-to-use cmdlets and comes with the ability to use .NET framework/C# in various scenarios. Windows includes a GUI tool, PowerShell ISE, which allows editing and debugging scripts in a useful way. A lesser known feature of PowerShell is the ability to compress to ZIP and extract files from a ZIP archive. This feature can be used in your own automation scenarios.

Advertisеment

PowerShell was initially released in November 2006 for Windows XP SP2, Windows Server 2003 SP1 and Windows Vista. This days, it is a different, open source product. PowerShell 5.1 introduced editions to the app. Microsoft first announced PowerShell Core edition on 18 August 2016, along with their decision to make the product cross-platform, independent of Windows, free and open source. It was released on 10 January 2018 to Windows, macOS and Linux users. Now it has its own support lifecycle. Microsoft plans to release one minor version for PowerShell Core 6.0 every six months. PowerShell Core 6.1 was released on 13 September 2018.

As you may already know, the ability to create a zip file without using third party tools appeared in Windows a long time ago. The first Windows version which had native ZIP archive support was Windows Me. All modern Windows versions support this archive format. To put a file or folder inside a zip archive in Windows 10, all you need to do is right click it and select Send to - Compressed (zipped) folder from the context menu. However, there are command line tools to compress your files to a zip archive. To get this functionality, you could use a third party solution.

If you are using PowerShell scripts to automate your tasks, you will be happy to know that PowerShell allows creating ZIP archives.  Here is how it can be done.

To Compress Files To ZIP Using PowerShell,

  1. Open PowerShell. Tip: You can add "Open PowerShell As Administrator" context menu.
  2. Type or copy-paste the following command:
    Compress-Archive -LiteralPath "path\to\your\files" -DestinationPath "path\to\your\archive.zip"
  3. Substitute the path portion in the command above with the actual values.

To Extract Files From ZIP Using PowerShell,

  1. Open PowerShell. Tip: You can add "Open PowerShell As Administrator" context menu.
  2. Type or copy-paste the following command:
    Expand-Archive -LiteralPath "path\to\your\archive.zip" -DestinationPath "Path\where\to\store\extracted files" -Force
  3. Substitute the path portion in the command above with the actual values.

You are done.

Related articles.

Support us

Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:

If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!

Advertisеment

Author: Sergey Tkachenko

Sergey Tkachenko is a software developer who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.

One thought on “Compress To ZIP and Extract From ZIP Using PowerShell”

  1. i clicked on that link by accidentally! please remove bad ads!
    https://i.postimg.cc/rsgv9хNM/bаd-ads.png

Leave a Reply

Your email address will not be published.

css.php
Using Telegram? Subscribe to the blog channel!
Hello. Add your message here.