Home
How to Use the Zip Command in Windows CMD and PowerShell
Windows does not feature a standalone legacy command named zip.exe in its traditional Command Prompt. However, users can perform robust file compression and extraction directly from the command line using two powerful built-in utilities: the tar command and PowerShell's Compress-Archive cmdlet.
If you are looking for a quick command to use in the standard Command Prompt (CMD), the most efficient method is:
tar -a -cf archive.zip source_folder
For users working within the PowerShell environment, the standard command is:
Compress-Archive -Path "C:\Source\*" -DestinationPath "C:\Output\Archive.zip"
This article provides a deep dive into these native tools, explaining syntax, advanced parameters, and automation strategies for Windows 10 and 11.
Using the tar Command in Windows CMD
Since Windows 10 (Build 17063), Microsoft has included a native implementation of the tar (Tape Archive) utility. While traditionally associated with Linux/Unix, the Windows version of tar supports the .zip format via the BSDtar library.
Basic Syntax for ZIP Creation
To create a simple ZIP archive in the Command Prompt, use the following structure:
tar -a -cf [archive_name.zip] [source_files]
-a: Tells the utility to use the archive suffix to decide which compressor to use (auto-compression). This ensures that if you name your file.zip, it will be compressed as a ZIP file.-c: Create a new archive.-f: Specifies the filename of the archive. This flag must be followed immediately by the desired output name.
Practical Examples with tar
-
Compressing a Single Directory:
tar -a -cf images.zip C:\Users\Admin\PicturesThis command bundles the entire Pictures folder intoimages.zipin the current working directory. -
Compressing Multiple Specific Files:
tar -a -cf project.zip file1.txt data.csv README.md -
Using Wildcards: To zip all log files in a directory:
tar -a -cf logs_backup.zip *.log
Extracting Files with tar
To unzip a file using the command line, the -x (extract) flag is used:
tar -xf archive.zip
To extract to a specific directory, add the -C (change directory) flag:
tar -xf archive.zip -C C:\TargetFolder
Mastering PowerShell Compress-Archive
For system administrators and users looking for more "Windows-centric" scripting capabilities, the Compress-Archive cmdlet in PowerShell is the standard tool. It is part of the Microsoft.PowerShell.Archive module.
Core Parameters
-Path: The source files or folders. Using a wildcard (*) inside a folder zips the contents, whereas pointing to the folder itself zips the directory structure.-DestinationPath: The full path where the ZIP file will be created.-CompressionLevel: Options includeOptimal(best compression, takes longer),Fastest(lowest compression, very quick), andNoCompression.-Update: Allows you to add files to an existing ZIP archive instead of creating a new one.
PowerShell Usage Scenarios
-
Zipping Contents Without the Root Folder: If you want the ZIP file to contain only the files inside a folder (not the folder itself), use:
Compress-Archive -Path C:\MyFiles\* -DestinationPath C:\Backups\MyFiles.zip -
Adding Files to an Existing Archive:
Compress-Archive -Path C:\NewData\update.txt -Update -DestinationPath C:\Backups\MyFiles.zip -
Handling Long Paths: PowerShell sometimes struggles with paths exceeding 260 characters. When using
Compress-Archive, ensure you are using a modern version of PowerShell (7+) or have enabled Long Paths in the Windows Registry to avoid "Path Too Long" errors.
The 2GB Limitation
It is important to note that the native PowerShell Compress-Archive cmdlet is built on the .NET ZipArchive class. This class historically has a limitation where it cannot create archives larger than 2GB. If your data exceeds this size, you should use the tar command or a third-party utility like 7-Zip.
Comparison of Native Windows CLI Compression Tools
| Feature | tar (CMD/PowerShell) | Compress-Archive (PowerShell) |
|---|---|---|
| Primary Environment | CMD / Windows Terminal | PowerShell / ISE |
| Max File Size | Virtually unlimited | 2GB (older .NET versions) |
| Format Support | .zip, .tar, .gz, .bz2 | .zip only |
| Compression Levels | Limited via flags | Optimal, Fastest, None |
| Ease of Scripting | Good for Batch files | Excellent for .ps1 scripts |
Advanced Automation with Scripts
Creating a Batch Script for Auto-Zipping
You can create a .bat file to automate the backup of specific folders. Create a file named backup.bat and paste the following:
-
Topic: Zip and unzip files | Microsoft Supporthttps://support.microsoft.com/de-DE/Windows/Experience/Storage-FileManagement/zip-and-unzip-files
-
Topic: Compress and decompress in Windows using commands (CMD and tar)https://mundobytes.com/en/How-to-compress-and-decompress-files-with-commands-in-Windows/
-
Topic: How to Create a Zip File on Windows (2026) | Technobezzhttps://www.technobezz.com/how-to-create-a-zip-file-on-windows