Compress-Archive
Use Compress-Archive to create a zip archive from files or folders.
Documentation: Microsoft Learn — PowerShell module reference
Syntax
See the command anatomy
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Compress-Archive [-Path] <String[]> [-DestinationPath] <String> [-CompressionLevel <String>] [-Update] [-Force] [<CommonParameters>]- Stage 1Compress-Archive
-Path -DestinationPath -CompressionLevel -Update -Force
Try it
PowerShell example · browser support is limited.
Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.
Follow the objects
Run the command to inspect each stage.
Examples
Compress-Archive -Path 'C:\Scripts\*.ps1'
Show reference output
Sample output · fictional data, shaped like the real thing
Directory: C:\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 10/9/2026 2:20 PM 18432 scripts.zip
Compress-Archive -Path 'C:\Scripts'
Show reference output
Sample output · fictional data, shaped like the real thing
Directory: C:\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 10/9/2026 2:21 PM 96256 all.zip
Parameters
Parameter definitions:
-Path-DestinationPath-CompressionLevel-Update-Force
Practical use and troubleshooting
Practical scenario: Use Compress-Archive when you need to create a zip archive from files or folders. Review syntax and sample output, then try an example in the browser lab. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.
Common error and fix: An existing destination archive can cause a failed create operation. Decide whether to update or replace it explicitly and verify which source files the input wildcard matches. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.
See also: Expand-Archive. Compress-Archive writes a ZIP archive; Expand-Archive extracts one. Confirm the source set before compression and the destination before extraction. Read the linked command before substituting it; similar names do not imply identical inputs or output.
Recap
Compress-Archive Use Compress-Archive to create a zip archive from files or folders.
Next: Expand-Archive