How to compress and decompress files with PowerShell on Windows

How to compress and decompress files with PowerShell on Windows. Besides compressing and decompressing files with Winrar software, we can also compress and decompress files with Powershell.

Besides compressing and decompressing files with Winrar software, we can also compress and decompress files with Powershell. In today's article, we will learn how to do this extremely unique operation.

1. Compress files and folders with PowerShell

To compress files in the PowerShell file, we will use the following command:

Compress-Archive -Path file path, root directory -DestinationPath file path, destination directory

Inside:

file path, root directory: Is the file path, root directory with the file extension name.

file path, destination directory: Is the file path, compressed directory + compressed file/folder name that you set.

Step 1: You open PowerShell by going to the Search menu (1) => search with the keyword PowerShell (2) => Windows PowerShell (3).

How to compress and decompress files with PowerShell on Windows Picture 1How to compress and decompress files with PowerShell on Windows Picture 1

Step 2: You enter the following command.

Compress-Archive -Path

How to compress and decompress files with PowerShell on Windows Picture 2How to compress and decompress files with PowerShell on Windows Picture 2

Next, you can get the file path to compress by right-clicking on the file (1) => Properties (2).

How to compress and decompress files with PowerShell on Windows Picture 3How to compress and decompress files with PowerShell on Windows Picture 3

Next, memorize the file address, file name (circled in red) or highlight the address and file name and press Ctrl + C to copy.

How to compress and decompress files with PowerShell on Windows Picture 4How to compress and decompress files with PowerShell on Windows Picture 4

Then, you enter or paste (press Ctrl + V) the address and file name into PowerShell.

How to compress and decompress files with PowerShell on Windows Picture 5How to compress and decompress files with PowerShell on Windows Picture 5

Step 3: Paste the command line behind.

-DestinationPath

How to compress and decompress files with PowerShell on Windows Picture 6How to compress and decompress files with PowerShell on Windows Picture 6

Next, enter the destination folder address after extracting the file and insert the file name and press Enter to compress the file.

How to compress and decompress files with PowerShell on Windows Picture 7How to compress and decompress files with PowerShell on Windows Picture 7

After done, the PowerShell command does not report an error.

How to compress and decompress files with PowerShell on Windows Picture 8How to compress and decompress files with PowerShell on Windows Picture 8

Step 4: Then, you open the folder and check the compressed file.

How to compress and decompress files with PowerShell on Windows Picture 9How to compress and decompress files with PowerShell on Windows Picture 9

Compressed file works fine and shows full archive as success.

How to compress and decompress files with PowerShell on Windows Picture 10How to compress and decompress files with PowerShell on Windows Picture 10

2. Compress multiple files with PowerShell

Compress multiple files with PowerShell, use the following command:

Compress-Archive -LiteralPath file path 1, file path 2, file path n -DestinationPath directory path, compressed file

Inside:

file path 1, file path 2, file path n: is the file path you need to compress.

folder path, compressed file: is the path to the compressed folder + the file name you set.

Step 1: After determining the path and name of the compressed file to create.

How to compress and decompress files with PowerShell on Windows Picture 11How to compress and decompress files with PowerShell on Windows Picture 11

Step 2: You enter the command with the syntax presented above to create the compressed file.

How to compress and decompress files with PowerShell on Windows Picture 12How to compress and decompress files with PowerShell on Windows Picture 12

Step 3: You check the compressed file after completion.

How to compress and decompress files with PowerShell on Windows Picture 13How to compress and decompress files with PowerShell on Windows Picture 13

If the compressed file works well and has enough files as you requested, it is successful.

How to compress and decompress files with PowerShell on Windows Picture 14How to compress and decompress files with PowerShell on Windows Picture 14

3. Extract files with PowerShell

Step 1: To decompress the file in this way, the compressed file must be in .zip format. Next, you specify the file name and directory containing the file.

How to compress and decompress files with PowerShell on Windows Picture 15How to compress and decompress files with PowerShell on Windows Picture 15

Step 2: You open PowerShell and execute the command with the following syntax.

Expand-Archive -LiteralPath archive path -DestinationPath destination directory path

Inside:

zip file path: Is the path to the compressed .zip file to decompress.

destination directory path: The path to the directory after extracting the file.

How to compress and decompress files with PowerShell on Windows Picture 16How to compress and decompress files with PowerShell on Windows Picture 16

Step 3: You check the file after extracting.

How to compress and decompress files with PowerShell on Windows Picture 17How to compress and decompress files with PowerShell on Windows Picture 17

If enough files and files work fine then success!

How to compress and decompress files with PowerShell on Windows Picture 18How to compress and decompress files with PowerShell on Windows Picture 18

With basic and easy to follow instructions with the command line in PowerShell, you can perform compression and decompression of files in a unique way. Good luck!

3.8 ★ | 13 Vote