The Archive module Microsoft.PowerShell.Archive
provides functions for storing files in ZIP archives (Compress-Archive
) and extracting them (Expand-Archive
). This module is available in PowerShell 5.0 and above.
In earlier versions of PowerShell the Community Extensions or .NET System.IO.Compression.FileSystem could be used.
Parameter | Details |
---|---|
CompressionLevel | (Compress-Archive only) Set compression level to either Fastest , Optimal or NoCompression |
Confirm | Prompts for confirmation before running |
Force | Forces the command to run without confirmation |
LiteralPath | Path that is used literaly, no wildcards supported, use , to specify multiple paths |
Path | Path that can contain wildcards, use , to specify multiple paths |
Update | (Compress-Archive only) Update existing archive |
WhatIf | Simulate the command |
See MSDN Microsoft.PowerShell.Archive (5.1) for further reference
Compress-Archive -Path C:\Documents\* -CompressionLevel Optimal -DestinationPath C:\Archives\Documents.zip
This command:
C:\Documents
Optimal
compressionC:\Archives\Documents.zip
-DestinationPath
will add .zip
if not present.-LiteralPath
can be used if you require naming it without .zip
.Compress-Archive -Path C:\Documents\* -Update -DestinationPath C:\Archives\Documents.zip
Documents.zip
with the new ones from C:\Documents
Expand-Archive -Path C:\Archives\Documents.zip -DestinationPath C:\Documents
Documents.zip
into the folder C:\Documents