Skip to content

Dear Internet Explorer user: Your browser is no longer supported

Please switch to a modern browser such as Microsoft Edge, Mozilla Firefox or Google Chrome to view this website's content.

Batch extract zip files with PowerShell

Use this simple PowerShell script to batch unzip large numbers of files at once.

Various pieces of computerised scientific equipment that I use generate large volumes of zip files which I have to unzip manually. Rather that suffer this tedium, I prefer to employ a PowerShell script that will:

The following instructions describe the process:

Install 7za

The PowerShell script relies upon a third-party script called 7-Zip, which can be downloaded for free from Sourceforge. Unzip the files and install 7za.exe to a known location on your Windows machine. Note the location.

Amend PowerShell script variables

There are two variables that need to be modified for the PowerShell script to run:

Amend the $path and $7za variables within the following code:

$path ="c:\path\to\your\files\*.zip" #location of zip files
$7za ="c:\path\to\7za.exe" #location of 7za 

$ZipFileList = Get-ChildItem -Path ($path) -Recurse;

foreach ($ZipFile in $ZipFileList) {
    mkdir -Path ('{0}\{1}' -f $ZipFile.Directory, $ZipFile.BaseName);
    $ArgumentList = 'x "{0}" -o"{1}\{2}\"' -f $ZipFile.FullName, $ZipFile.Directory, $ZipFile.BaseName;
    Start-Process -FilePath ($7za) -ArgumentList $ArgumentList -Wait;
}

Execute the script in PowerShell and the files will be unzipped.

Another option

If you don’t want PowerShell to conduct a recursive search within the target folder, delete -Recurse from the script.

Credit

This script is based on the work of Trevor Sullivan.

   

Comments

No comments have yet been submitted. Be the first!

Have Your Say

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.