Unzipping ZIP Files with any PowerShell Version

by Jul 30, 2015

If you do not have PowerShell 5.0 and .NET Framework 4.5 is not available, here is an approach to unzip ZIP files that uses the native Windows shell support.

If you have installed custom ZIP file extensions for the explorer, this approach may not work anymore, though.

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

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

$shell = New-Object -ComObject Shell.Application
$sourceFolder = $shell.NameSpace($Source)
$destinationFolder = $shell.NameSpace($Destination)
$DestinationFolder.CopyHere($sourceFolder.Items())

if ($ShowDestinationFolder) 
{
  explorer.exe $Destination
}

The advantage of this approach is that you get the default shell dialogs when overwriting files. Also, this approach can unpack CAB files as well.

Twitter This Tip! ReTweet this Tip!