In the PowerShell window, type in the following command:
1 |
Compress-Archive -Path [Source-Path] -DestinationPath [Destination-Path] |
Make sure to change to the actual path of the file you want to zip and with the location where you want to save the file.
Compression Level
There are three types of compression level.
- Fastest − Uses the fastest compression to reduce the processing time. It can lead to 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
1 2 3 4 5 6 |
$compress = @{ Path = "C:\Reference\Draftdoc.docx", "C:\Reference\Images\*.vsd" CompressionLevel = "Fastest" DestinationPath = "C:\Archives\Draft.Zip" } Compress-Archive @compress |
*.vsd is wildcard here for multiple files with the same extension.
compress Root directory and below sub-directories and files
1 |
Compress-Archive -Path E:\SourceLocation -DestinationPath E:\Archives\ZIPFileName.Zip |
compress all the files and sub-directories below the root “SourceLocation” folder
1 |
Compress-Archive -Path E:\SourceLocation\* -DestinationPath E:\DestinationLocation\ZIPFileName.Zip |
compress only the files in the “SourceLocation” folder.
1 |
Compress-Archive -Path E:\SourceLocation\*.* -DestinationPath E:\DestinationLocation\ZIPFileName.Zip |
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.
Hi Arjun
Great article, I have a question. Hope you can answer. Here’s my code that zips all the folders into a single folder.
What I want to do it to copy this zip folder and send it to a shared network network location which should be a parameter.
I've tried many different stuff but haven't gone through yet. I just tried:
Are you trying to copy to a different machine?
Try this –
copy-item -Path $sourcePath -Destination \\mynetwork\shared\projects
Thanks for the reply Arjun, I figured it out.
Cool:)