Home » How To » How to Zip & Unzip Files Using PowerShell – Compress Files

How to Zip & Unzip Files Using PowerShell – Compress Files

You can zip files and folders and extract zip files using the PowerShell. Here’re the commands to zip and unzip files using PowerShell in Windows.

To share multiple files or to save some disk space, you can compress them into a zip file. You can also encrypt zip files and password-protect them with just a few clicks to keep the contents from prying eyes. In Windows, there are several different ways to compress a file or folder. For example, you can right-click on a file or folder and select the “Send to → Compressed folder” to compress it. For added functionality, there are dedicated programs like 7-zip, WinRAR, etc..

Alternatively, you can also use a simple PowerShell command to zip compress files. When needed, you can use another PowerShell command to extract or unzip files. This method is particularly useful when creating custom PowerShell scripts.

In this quick guide, let me share with you the commands to zip and unzip files using PowerShell commands.

Jump to:

How to Zip Files using PowerShell

To compress files using PowerShell, you can use the Compress-Archive cmdlet. All you have to do is point the files you want to compress and a destination to save the zip file. Here are the exact steps.

  1. Open the Start menu by pressing the Start key on your keyboard.
  2. Type “PowerShell” and press Enter to open it.
  3. After opening the PowerShell window, execute the below command to zip files. Replace <FilePath> with the actual path of the file you want to compress and <DestinationPath> with the folder path of where you want to save the compressed file.
    Compress-Archive -LiteralPath '<FilePath>' -DestinationPath '<DestinationPath>'
  4. As soon as you execute the command, PowerShell will zip the file and saves it in the specified destination.
    Powershell-command-to-compress-zip-file-070820
  5. You can close the PowerShell window.

How to Zip Multiple Files or Folder using PowerShell

If you want to compress multiple files or a folder containing files and/or sub-folders, you can do that too from the PowerShell. Here’re the steps to zip multiple files or folders using the PowerShell.

  1. First, put all the files you want to compress are in a single folder.
  2. Next, open the Start menu.
  3. Search for PowerShell and open it.
  4. In the PowerShell window, execute this command. Replace <FolderPath> with the actual folder path you want to compress and <DestinationPath> with the destination path where you want to save the compressed zip file.
    Compress-Archive -LiteralPath '<FolderPath>' -DestinationPath '<DestinationPath>'
  5. Depending on the folder size or number files, it can take some time to complete the compressions process.
    Powershell-command-to-compress-zip-multiple-files-folder-070820
  6. Once done, close the PowerShell window.

You can find the compressed zip file in the destination you set in the above command.

Extract / Unzip Files Using PowerShell

Just as you can compress files with PowerShell, you can also extract files with PowerShell’s Expand-Archive cmdlet. Just point the PowerShell to the zip file you want to extract and provide a destination directory.

  1. Open the PowerShell window.
  2. In the PowerShell, execute the below command while replacing <ZipFilePath> and <DestinationPath> with the actual zip file path and destination folder path respectively.
    Expand-Archive -LiteralPath <ZipFilePath> -DestinationPath <DestinationPath>
  3. Once extracted, close the PowerShell window.
    Powershell-command-to-unzip-and-extract-zip-file-070820

You can find the extracted files in a folder in the destination path.

That is all. I hope that helps. If you are stuck or need some help, comment below and I will try to help as much as possible.

Leave a Comment

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

Scroll to Top