Zipping a file or folder reduces its size and makes it easy to share the zipped file through different mediums. Compressing a file also saves the disk space. There are different ways you can zip or unzip a file; i.e. using the built-in compressing tool, or by installing a third-party app from the internet. The other way to compress a file is by using Windows PowerShell.
In this guide, we will show you how to zip a file using Windows PowerShell.
Compressing a File Using PowerShell
Follow the guide to learn how it could be done:
- Launch PowerShell on your Windows 10 PC from the Start menu. Type in the following command on PowerShell:
Compress-Archive -LiteralPath <PathToFile> -DestinationPath <PathToDestination>
Replace the <PathToFile> with the actual path that consists of the file that you want to compress and <PathToDestination> with the path where you want to save the compressed file.
You can also give the zipped file a name with the destination path or PowerShell will save it as a “.zip” in the specified destination.
- If you want to compress the whole folder with its sub-folders as well, type in the following command in Windows PowerShell:
Compress-Archive -LiteralPath <PathToFolder> -DestinationPath <PathToDestination>
Here, replace <PathToFolder> with the location of the folder that you want to compress with all its subfolders, and <PathToDestination> where you want to save the compressed folder.
Unzipping Files in Windows PowerShell
Windows PowerShell not only allows the user to Compress the files and folders, but they can also unzip the compressed files. The procedure is even easier than compressing a file or folder. All you have to provide is the source path and the destination path.
To unzip a file in PowerShell type in the following command:
Expand-Archive -LiteralPath <PathToZipFile> -DestinationPath <PathToDestination>
Here, replace the <PathToZIpFile> with the actual path of the zipped file, and <PathToDestination> where you want to unzip the file.
You can skip the -DestinationPath parameter, Powershell will unzip the content in the same directory as the zipped file. It will create a new folder named “Archive” where the un-zipped file will reside.