
close
close
Chance to win $250 in Petri 2023 Audience Survey
In continuing my exploration of what’s new in PowerShell 5.0, I think you’ll like the new cmdlets designed to work with ZIP files. PowerShell now includes a few basic cmdlets for creating and expanding archives. They probably aren’t as full featured as other compression utilities like WinRAR, but they are easy to use. Let’s take a look.
The cmdlets are part of the Microsoft.PowerShell.Archive module.
The new archive cmdlets (Image Credit: Jeff Hicks)
dir c:\work\*.xml -Recurse | Compress-Archive -DestinationPath C:\work\XMLData.zip
If the zip file already exists, then you will get an error. So if you want to create something totally new, you need to test for the archive first and delete it. Otherwise, you can use the Update parameter, which is self explanatory.
dir c:\work\*.xml -Recurse | Compress-Archive -DestinationPath C:\work\XMLData.zip -update
You’ll end up with a zip file like this:
The new zip file (Image Credit: Jeff Hicks)
dir c:\work\*.xml -Recurse | Compress-Archive -DestinationPath C:\work\XMLData-Optimal.zip dir c:\work\*.xml -Recurse | Compress-Archive -DestinationPath C:\work\XMLData-Fastest.zip -CompressionLevel Fastest dir c:\work\*.xml -Recurse | Compress-Archive -DestinationPath C:\work\XMLData-None.zip -CompressionLevel NoCompression
Of course, your compression rates will vary depending on the file types. But here’s what I end up with.
Comparing rates (Image Credit: Jeff Hicks)
Optimal statistics (Image Credit: Jeff Hicks)
Fastest statistics (Image Credit: Jeff Hicks)
No compression statistics (Image Credit: Jeff Hicks)
Compress-Archive -Path c:\work -DestinationPath d:\temp\work.zip -CompressionLevel Fastest -Update
You can see the folder structure in the zip file
An archive with folder structure (Image Credit: Jeff Hicks)
More in PowerShell
Most popular on petri