You can zip files and folders and extract zip files using the PowerShell. Here’re the commands to zip and unzip files using PowerShell in Windows.
To share multiple files or to save some disk space, you can compress them into a zip file. You can also encrypt zip files and password-protect them with just a few clicks to keep the contents from prying eyes. In Windows, there are several different ways to compress a file or folder. For example, you can right-click on a file or folder and select the “Send to → Compressed folder” to compress it. For added functionality, there are dedicated programs like 7-zip, WinRAR, etc..
Alternatively, you can also use a simple PowerShell command to zip compress files. When needed, you can use another PowerShell command to extract or unzip files. This method is particularly useful when creating custom PowerShell scripts.
In this quick guide, let me share with you the commands to zip and unzip files using PowerShell commands.
- How to Zip Files using PowerShell
- How to Zip Multiple Files or Folder using PowerShell
- Extract / Unzip Files Using PowerShell
How to Zip Files using PowerShell
To compress files using PowerShell, you can use the Compress-Archive cmdlet. All you have to do is point the files you want to compress and a destination to save the zip file. Here are the exact steps.
- Open the Start menu by pressing the Start key on your keyboard.
- Type “PowerShell” and press Enter to open it.
- After opening the PowerShell window, execute the below command to zip files. Replace <FilePath> with the actual path of the file you want to compress and <DestinationPath> with the folder path of where you want to save the compressed file.
Compress-Archive -LiteralPath '<FilePath>' -DestinationPath '<DestinationPath>'
- As soon as you execute the command, PowerShell will zip the file and saves it in the specified destination.
- You can close the PowerShell window.
How to Zip Multiple Files or Folder using PowerShell
If you want to compress multiple files or a folder containing files and/or sub-folders, you can do that too from the PowerShell. Here’re the steps to zip multiple files or folders using the PowerShell.
- First, put all the files you want to compress are in a single folder.
- Next, open the Start menu.
- Search for PowerShell and open it.
- In the PowerShell window, execute this command. Replace <FolderPath> with the actual folder path you want to compress and <DestinationPath> with the destination path where you want to save the compressed zip file.
Compress-Archive -LiteralPath '<FolderPath>' -DestinationPath '<DestinationPath>'
- Depending on the folder size or number files, it can take some time to complete the compressions process.
- Once done, close the PowerShell window.
You can find the compressed zip file in the destination you set in the above command.
Extract / Unzip Files Using PowerShell
Just as you can compress files with PowerShell, you can also extract files with PowerShell’s
Expand-Archive cmdlet. Just point the PowerShell to the zip file you want to extract and provide a destination directory.
- Open the PowerShell window.
- In the PowerShell, execute the below command while replacing <ZipFilePath> and <DestinationPath> with the actual zip file path and destination folder path respectively.
Expand-Archive -LiteralPath <ZipFilePath> -DestinationPath <DestinationPath>
- Once extracted, close the PowerShell window.
You can find the extracted files in a folder in the destination path.
That is all. I hope that helps. If you are stuck or need some help, comment below and I will try to help as much as possible.