
Apart from using the third party tool for files zipping or unzipping, you can use the Windows PowerShell to execute the same activity.
Before you proceed further, the commands shown below is based on PowerShell version 5. The zip / unzip commands are firstly introduced in version 5 and you won’t find it at earlier version.
Compress-Archive (Zip)
Example 1: Create zip file
Compress-Archive -Path C:\FolderA\File1.txt,
C:\FolderB\File2/txt -CompressionLevel Optimal
-DestinationPath C:\FolderC\File3.zip
Example 2: Create zip file using LiteralPath
Compress-Archive -LiteralPath 'C:\FolderA\File1.txt',
'C:\FolderB\File2.txt' -CompressionLevel Optimal
-DestinationPath C:\FolderC\File3.zip
Example 3: Create zip with wildcard characters
Compress-Archive -Path C:\FolderA\* -CompressionLevel
Fastest -DestinationPath C:\FolderC\FolderA.zip
Example 4: Update an existing zip file
Compress-Archive -Path C:\FolderA\* -Update
-DestinationPath C:\FolderC\FolderA.zip
Example 5: Create zip from an entire folder
Compress-Archive -Path C:\FolderA
-DestinationPath C:\FolderC\FolderA.zip
Parameter
| Parameter | Description |
|---|---|
| -CompressionLevel | Fastest (Fastest compression method) NoCompression (No compression) Optimal (Default value) |
| -Confirm | Prompt confirmation before execution. |
| -DestinationPath | The location of zip output file. |
| -Force | Force command to run without user confirmation. |
| -LiteralPath | Specify the path or paths to the files for zip. Different to Path parameter as the LiteralPath value is used exactly as it is typed. |
| -Path | The location of source files or folders to be zip. |
| -Update | Add newer or replace files to an existing zip. |
| -WhatIf | Shows what would happen if the command runs. |
Syntax
Compress-Archive
-LiteralPath or [-Path] <String[]>
[-DestinationPath] <String>
[-CompressionLevel <String>]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Expand-Archive (unzip)
Example 1: Extract zip file to the specific folder
Expand-Archive -LiteralPath C:\FolderC\File3.zip
-DestinationPath C:\FolderD
Example 2: Extract zip file to the current folder
Expand-Archive -Path File3.zip -DestinationPath C:\FolderC
Parameter
| Parameter | Description |
|---|---|
| -Confirm | Prompt confirmation before execution. |
| -DestinationPath | The location of unzip. |
| -Force | Force command to run without user confirmation. |
| -LiteralPath | Specify the path to the zip file. Different to Path parameter as the LiteralPath value is used exactly as it is typed. |
| -Path | Specify the path to the zip file. |
| -WhatIf | Shows what would happen if the command runs. |
Syntax
Expand-Archive
-LiteralPath or [-Path] <String>
[[-DestinationPath] <String>]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]

