Unzipping ZIP Files with PowerShell 3.0 and 4.0

by Jul 29, 2015

ZIP file support was introduced in PowerShell 5.0, but if you have installed the .NET Framework 4.5 and possibly want more control over the unzipping process, try this:

#requires -Version 2
# .NET Framework 4.5 required!

Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop

$Source = 'C:\somezipfile.zip'
$Destination = 'C:\somefolder'
$Overwrite = $true
$ShowDestinationFolder = $true

if ((Test-Path $Destination) -eq $false) 
{
 $null = mkdir $Destination 
}

$Content = [IO.Compression.ZipFile]::OpenRead($Source).Entries
$Content | 
 ForEach-Object -Process {
    $FilePath = Join-Path -Path $Destination -ChildPath $_
                [IO.Compression.ZipFileExtensions]::ExtractToFile($_,$FilePath,$Overwrite)
            }
if ($ShowDestinationFolder) 
{
 explorer.exe $Destination 
}

Twitter This Tip! ReTweet this Tip!