PowerShell Genie

Compress-Archive

Use Compress-Archive to create a zip archive from files or folders.

Command 1 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — PowerShell module reference

Syntax

1PS> Compress-Archive [-Path] <String[]> [-DestinationPath] <String> [-CompressionLevel <String>] [-Update] [-Force] [<CommonParameters>]
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>]
  1. Stage 1Compress-Archive-Path -DestinationPath -CompressionLevel -Update -Force

    Try it

    Windows PowerShell

    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.

    Interactive simulation · fictional data

    Examples

    Compress-Archive -Path 'C:\Scripts\*.ps1'

    1PS> Compress-Archive -Path 'C:\Scripts\*.ps1' -DestinationPath 'C:\Temp\scripts.zip'
    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'

    1PS> Compress-Archive -Path 'C:\Scripts' -DestinationPath 'C:\Temp\all.zip' -CompressionLevel Fastest
    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

    PowerShell module reference on Microsoft Learn

    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.

    Compress-Archive reference on Microsoft Learn

    Recap

    Compress-Archive Use Compress-Archive to create a zip archive from files or folders.

    Next: Expand-Archive
    Genie guideCompress-Archive

    Use Compress-Archive to create a zip archive from files or folders. The console below is pre-loaded — run it, then change a value and run it again.