How to zip and unzip files using Windows PowerShell

The PowerShell shell is useful for various tasks such automation and configurations management.

How to zip and unzip files using Windows PowerShell
Artwork

The PowerShell shell is useful for various tasks such automation and configurations management. PowerShell comes pre-installed on windows. It was built to be somewhat a successor to CMD packed with all CMD features and more. CMD is the default command line interpreter for windows.

In this guide we will be simply covering how to zip and unzip files using PowerShell.

ZIP using PowerShell

In order to zip files using PowerShell, PowerShell uses the Compress-Archive module built in to PowerShell.

To simply compress a file we use the below schema:

Compress-Archive -Path <folder/file-path> -DestinationPath <new-zip-filename.zip>

Unzip using PowerShell

In order to unzip files using PowerShell, PowerShell uses the Expand-Archive module built in to PowerShell.

To simply unzip a file we use the below schema:

Expand-Archive <filename.zip> -DestinationPath <unzip-to-folder>

Conclusion

Zipping and unzipping files using PowerShell is useful in scripting scenarios where you don't have access to graphical user interface (GUI).

Resources:

Microsoft.PowerShell.Archive Module - PowerShell
This section contains the help topics for the cmdlets that are installed with the PowerShell Microsoft.PowerShell.Archive module. The Archive module contains cmdlets that let you create and extract archive or ZIP files.
Expand-Archive (Microsoft.PowerShell.Archive) - PowerShell
The Expand-Archive cmdlet extracts files from a specified zipped archive file to a specified destination folder. An archive file allows multiple files to be packaged, and optionally compressed, into a single zipped file for easier distribution and storage.

Subscribe to Bluedoa Digest

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
alexander@example.com
Subscribe