Skip to content

PowerShell zip files and folder

Last updated on November 22, 2022

In the PowerShell window, type in the following command:

Compress-Archive -Path [Source-Path] -DestinationPath [Destination-Path]

Make sure to change the actual path of the file you want to zip and the location where you want to save the file.

Compression Level

There are three types of compression levels.

  • Fastest − Uses the fastest compression to reduce the processing time. It can lead to a larger file size.
  • Optimal − Normal compression level. Processing time depends on the size of the file. This is the default compression level if you don’t use the compression parameter.
  • NoCompression − Doesn’t compress the source files. This means the size of the actual folders and files are the same after the zipped only there is no compression ratio.

Compress files to create an archive file

$compress = @{
  Path = "C:\Reference\Draftdoc.docx", "C:\Reference\Images\*.vsd"
  CompressionLevel = "Fastest"
  DestinationPath = "C:\Archives\Draft.Zip"
}
Compress-Archive @compress

*.vsd is a wildcard here for multiple files with the same extension.

compress the root directory and below sub-directories and files

Compress-Archive -Path E:\SourceLocation -DestinationPath E:\Archives\ZIPFileName.Zip

compress all the files and sub-directories below the root “SourceLocation” folder

Compress-Archive -Path E:\SourceLocation\* -DestinationPath E:\DestinationLocation\ZIPFileName.Zip

compress only the files in the “SourceLocation” folder.

Compress-Archive -Path E:\SourceLocation\*.* -DestinationPath E:\DestinationLocation\ZIPFileName.Zip

0 0 votes
Article Rating
Subscribe
Notify of
guest

5 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments