Site icon Dotnet Helpers

Use PowerShell to create compressed ZIP files

In many scenarios, we will have a requirements for handling to create zip archives or extract files from existing archives with programmatically .  From PowerShell 5.0, it provided two cmdlet for creating and extracting zip files. The Compress-Archive cmdlet enables you to create new archives from folders or individual files to add files to archives; Extract-Archive can be used to unzip files. Let we get in to this with very two simple example.

Example #1 : Create an Simple archive file

The below command will zip the Dotnethelpers_PowershellArticles folder and create an archive called PowershellArticles.zip in the Archives folder:

–Path : Parameter to specify the folder/file path which you want to compress.
–DestinationPath : Parameter to specify the name of the archive.

Example: 2 : Create an archive file using -LiteralPath

The below command creates PowerShellMVCArticles.Zip file by compressing two folders that is Dotnethelpers_PowershellArticles and PowerShellMVCArticles.Zip specified by the LiteralPath parameter instead of -path cmdlet.

Fastest: This method available to decrease processing time; this can result in larger file sizes.
NoCompression: Do not compress the source files.
Optimal: Processing time is dependent on file size.

OUTPUT

What do you think?

I hope you have an idea of  How to Use PowerShell to create compressed ZIP files. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.

Exit mobile version