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.
1 2 3 4 5 6 7 8 |
#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
1 2 3 4 5 6 7 8 9 |
$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