How to Unzip a File to Folder in PowerShell (With Example)


You can use the following basic syntax to unzip a file to a folder in PowerShell:

Expand-Archive c:\this\path\some_data.zip -DestinationPath c:\this\path

This particular example unzips the file named some_data.zip from a specific folder into a folder with the path c:\this\path

The original zip file is kept in the original folder.

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

Example: How to Unzip a File to Folder in 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 a single zip file named all_data.zip.

Suppose that we would like to unzip this zip file to the same folder that it currently exists in.

We can use the following syntax to do so:

Expand-Archive c:\users\bobbi\data2\all_data.zip -DestinationPath $my_folder

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

PowerShell unzip file to folder

We can see that the zip file has been unzipped to the folder that it currently existed in.

We see that the zip file contained three individual files:

  • coaches.txt
  • players.txt
  • teams.txt

Also notice that the original zip file all_data.zip still exists in the folder.

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