Working with Zip Files and Compressed Folder

Compressing folders is usually the easiest way to save disk space or network bandwidth moving data or files across different nodes, especially when is required to do it efficiently.

Powershell 5 offers a built-in cmd-let to work with archives.

#Requires -Version 5.0
# the maximum file size that you can compress by using Compress-Archive is currently 2 GB

#Compress 
Compress-Archive -Path "PathToCompress" -DestinationPath "FileName.zip"

#Expand 
Expand-Archive -Path "FileName.zip" -DestinationPath "DestinationPath"

Let’s now try using something different such as 7-zip  (http://www.7-zip.org/):

  • Using Powershell versions older than 5.0
  • Compress more than 2 GB
  • Protect archive with password
$SevenZipInstallPath = "C:\Program Files\7-Zip\7z.exe"  
set-alias SevenZip  $SevenZipInstallPath 
# use remove-item alias:SevenZip  if you want to remove t later

#Compress
SevenZip a  "Filename.zip" "InputDir" 

#Estract 
SevenZip e "FileName.Zip" -o"OutputDir"


Tip: Follow this tutorial and examples to learn more about 7Zip

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.