Have some files and need to create a zip archive using Powershell? No problem, it’s built in!
Since PowerShell version 5+, there is an Compress-Archive command built in:
Compress-Archive -Path file.txt, file2.txt -CompressionLevel Fastest -DestinationPath C:\compress\to\here\myzipfile.zip
Note: There’s a 2 GB max file size limit due to a limitation of the underlying API.
Not sure which version of PowerShell you have?
$PSVersionTable.PSVersion
Use Splatting
As seen in the example these lines can get long! Splatting can help with that. Here’s an example:
$compress = @{
Path = "C:\Documents\file.txt", "C:\Documents\file1.txt"
CompressionLevel = "Fastest"
DestinationPath = "C:\Documents\myzipfile.zip"
}
Compress-Archive @compress
Find more information:
man Compress-Archive
Need to Extract a zip file?
Check out Expand-Archive in PowerShell