PowerShell: How to Unzip All Files in Folder


You can use the following basic syntax to unzip all files in a folder using PowerShell:

gci c:\my\path -Filter *.zip | Expand-Archive -DestinationPath c:\new\path

This particular example unzips all zip files in the folder located at c:\my\path and extracts all of the files to the folder located at c:\new\path.

All of the original zip files are kept in the original folder.

Note: In this example we use gci as an alias for the Get-ChildItem cmdlet.

The following example shows how to use this syntax in practice.

Example: How to Unzip All Files in Folder Using PowerShell

Suppose that we have a directory with the following path:

  • c:\users\bobbi\data2

We can use the following syntax to list out all folders and files in this directory:

$my_folder = "c:\users\bobbi\data2"
Dir $my_folder

The following screenshot shows how to use this syntax in practice:

 

We can see that the directory contains two zip files:

  • conference_data.zip
  • team_data.zip

Suppose that we would like to unzip each of these zip files to the same folder that they currently exist in.

We can use the following syntax to do so:

gci $my_folder -Filter *.zip | Expand-Archive -DestinationPath $my_folder

The following screenshot shows how to use this syntax in practice:

PowerShell unzip all files in folder

We can see that both zip files have been unzipped and the individual files within them are now all shown in the data2 folder.

Also notice that the original zip files conference_data.zip and team_data.zip both still exist in the folder.

Note that we used the -Filter operator to filter for the files in the folder that had a .zip extension and then used the Expand-Archive method to unzip each of these zip folders.

Note: You can find the complete documentation for the Expand-Archive method here.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Rename File Extension of Multiple Files
PowerShell: How to List Files in Directory by Date
PowerShell: How to Replace Every Occurrence of String in File

Leave a Reply