Bootstrap FreeKB - PowerShell - Unzip files using Expand-Archive
PowerShell - Unzip files using Expand-Archive

Updated:   |  PowerShell articles

If you are using PowerShell major version 5 or higher, you can use Expand-Archive to unzip .zip files. The $PSVersionTable.PSVersion command can be used to display your PowerShell version.

C:\Users\JohnDoe> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      20348  1366

 

In this example, The example.zip file will be unzipped into the C:\temp directory.

Expand-Archive C:\example.zip -DestinationPath C:\temp

 

Here is how you could get all of the .zip files in a directory that contain "foo" in the file name and to extract each file to the C:\temp directory.

$files = Get-ChildItem -file -path "C:\path\to\dir" | Where-Object name -like "*foo*.zip"

foreach ($file in $files) {
    Write-Host Will extract $file.FullName to C:\temp
    Expand-Archive $file.FullName -DestinationPath C:\temp
}

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 50c62f in the box below so that we can be sure you are a human.