Zip/unzip

How to compress files using PowerShell on Windows 10

You can use PowerShell to compress and extract files from zip containers, and in this guide, you'll learn the steps on how to do it.

Zip and unzip files on Windows 10 using PowerShell

On Windows 10, you can use a zip file to package and compress files and folders for easier sharing or storing files that you don’t use frequently.

Although you can use File Explorer to quickly create a zip file or extract the contents of a zipped file, you can also use PowerShell to perform the same tasks more efficiently. In addition, you can even select the compression ratio to zip files even faster or optimize to save space.

In this guide, you’ll learn the steps to zip and unzip files and folders using PowerShell commands on Windows 10.

How to zip files using PowerShell

To compress files using zip with PowerShell on Windows 10, use these steps:

  1. Open Start on Windows 10.

  2. Search for PowerShell, right-click the top result, and click the Run as administrator option.

  3. Type the following PowerShell command to compress and zip a folder with files and press Enter:

    Compress-Archive -Path C:\SOURCE\PATH\TO\YOUR\FILES\* -CompressionLevel Optimal -DestinationPath C:\DESTINATION\PATH\ZIPPEDFILE.zip
    Zip files using PowerShell
    Zip files using PowerShell

    In the command make sure to change the source and destination with your specific paths. The wildcard “*” tells the command to compress all the contents of the source folder.

Once you complete the steps, PowerShell will compress the folder and all its content creating a new .zip file with a compressed version of the files.

How to add more files to zip using PowerShell

To update zip file with more files using PowerShell, use these steps:

  1. Open Start.

  2. Search for PowerShell, right-click the top result, and click the Run as administrator option.

  3. Type the following command to update the zip file with additional files and press Enter:

    Compress-Archive -Path C:\SOURCE\PATH\TO\YOUR\FILES -Update -DestinationPath C:\DESTINATION\PATH\ZIPPEDFILE.zip
    Update zip file using PowerShell
    Update zip file using PowerShell

    In the command make sure to change the source and destination with your specific paths.

After you complete the steps, the zip folder will be updated with the new files that you specified in the command.

How to change zip compression ratio using PowerShell

To change the compression ratio of zip file using PowerShell, use these steps:

  1. Open Start.

  2. Search for PowerShell, right-click the top result, and click the Run as administrator option.

  3. Type the following PowerShell command to compress files with different ratio and press Enter:

    Compress-Archive -Path C:\SOURCE\PATH\TO\YOUR\FILES\* -CompressionLevel Fastest -DestinationPath C:\DESTINATION\PATH\ZIPPEDFILE.zip
    Compression ratio for zip file using PowerShell
    Compression ratio for zip file using PowerShell

    In the command make sure to change the source and destination with your specific paths.

If you want to specify the zip compression ratio make sure to set the CompressionLevel flag with the ratio you want:

  • Fastest: Uses less time to compress files, but it may result on zip file being larger.
  • NoCompression: Uses no compression resulting on a zip file that is the same size as the total amount of the uncompressed files.
  • Optimal: Uses more time, but it compresses the files with the highest ratio.

Once you complete the steps, the zip folder will be created using the compression ratio that you specified.

How to unzip files using PowerShell

To uncompress zip file using PowerShell on Windows 10, use these steps:

  1. Open Start.

  2. Search for PowerShell, right-click the top result, and click the Run as administrator option.

  3. Type the following command to unzip a folder with files and press Enter:

    Expand-Archive -Path C:\SOURCE\PATH\TO\YOUR\ZIPFILE\ZIPPED.zip -DestinationPath C:\DESTINATION\PATH\UNZIP
    Extract files from zip using PowerShell on Windows 10
    Extract files from zip using PowerShell on Windows 10

    In the command make sure to change the source and destination with your specific paths.

After you complete the steps, PowerShell with extract all the files and folders from the zip container that you specified.

While we’re focusing this guide on Windows 10, you can also use these instructions on Windows 8.1 and Windows 7.