Compress-Archive is a PowerShell cmdlet to create an archive, or zipped file, from specified files and folders. Supported since PowerShell 5.0.

However, there are some traps you need to be aware of.

Compress-Archive Ignores Hidden Files

Hidden files in directories are ignored when creating a zip using Compress-Archive cmdlet on Windows. Even if you explicitly pass them in using the -Path or -LiteralPath argument, Compress-Archive cannot see them and error out in that case.

The only workaround is to remove the hidden attribute from the file before running Compress-Archive or use other CLI tools such as 7z.


Compress-Archive Ignores Empty Directories Passed on CLI

Take the following command as an example, any empty directory under My/Content will be ignored and not packed into the zip file.

Compress-Archive My/Content/* Zip

If you specify an empty directory directly on command line like this:

Compress-Archive Emtpry/Directory Zip

Then the zip file will not get created at all.

Note that empty directories under directories specified on CLI (nested empty directories) do get included into zip file.