In this post, we’ll show you how to use PowerShell to unzip files quickly and easily.
PowerShell is a powerful command-line tool that can help you perform a wide range of tasks, including extracting the contents of zip files.
The Expand-Archive
cmdlet
PowerShell provides a built-in cmdlet called Expand-Archive
that allows you to extract the contents of zip files. The Expand-Archive
cmdlet is available in PowerShell 5.0 and later versions.
The Expand-Archive
cmdlet takes two parameters:
-Path
: specifies the path to the zip file that you want to extract.-DestinationPath
: specifies the path to the directory where you want to extract the contents of the zip file.
For example, to extract the contents of a file named example.zip
located in C:\temp\
to a directory named example
located in C:\
, you can use the following command:
Expand-Archive -Path "C:\temp\example.zip" -DestinationPath "C:\example"
By default, Expand-Archive
will overwrite any existing files with the same name as files in the archive. If you want to skip overwriting files, you can use the -NoClobber
parameter, like this:
Expand-Archive -Path "C:\temp\example.zip" -DestinationPath "C:\example" -NoClobber
This will extract the files in the zip archive to C:\example
, but it will not overwrite any existing files.
You can also use the -Force
parameter to force Expand-Archive
to overwrite existing files, like this:
Expand-Archive -Path "C:\temp\example.zip" -DestinationPath "C:\example" -Force
This will extract the files in the zip archive to C:\example
and overwrite any existing files with the same name.
Extract only specific files
If you want to extract only specific files from the archive, you can use the -Include
parameter to specify a wildcard pattern that matches the names of the files you want to extract. For example, to extract only the files with a .txt
extension, you can use the following command:
Expand-Archive -Path "C:\temp\example.zip" -DestinationPath "C:\example" -Include "*.txt"