August 14th, 2015

PowerTip: Use PowerShell 5 to Compress Files

Doctor Scripto
Scripter

Summary: Learn how to use the new Compress-Archive cmdlet to compress selected files in Windows PowerShell 5.0.

Hey, Scripting Guy! Question How can I compress a bunch of files on my computer that match a pattern I supply to Get-ChildItem?

Hey, Scripting Guy! Answer Use Get-ChildItem to find the files you want to compress, and pipe the results to the Compress-Archive cmdlet,
           for example (gci is an alias for Get-ChildItem):

gci c:\fso\*.txt | Compress-Archive -DestinationPath c:\fso\myarchive.zip

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.