
close
close
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.
advertisment
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 from Jeff Hicks
advertisment
Petri Newsletters
Whether it’s Security or Cloud Computing, we have the know-how for you. Sign up for our newsletters here.
advertisment
More in PowerShell
Microsoft’s New PowerShell Crescendo Tool Facilitates Native Command-Line Wraps
Mar 21, 2022 | Rabia Noureen
Most popular on petri
Log in to save content to your profile.
Article saved!
Access saved content from your profile page. View Saved
Join The Conversation
Create a free account today to participate in forum conversations, comment on posts and more.
Copyright ©2019 BWW Media Group