PowerShell Scripts, Tips, Expert Advices, Forums, and Resources

Geek Sync Live

Welcome to PowerShell.com, the educational and community site for Windows PowerShell People. Get a quick overview.


As a Powershell.com member you will have access to:

  • Daily PowerShell tips written by Microsoft MVPs and other leading Windows PowerShell experts
  • Free Windows PowerShell advice and training provided by Microsoft MVPs and other leading Windows PowerShell experts
  • Access to leading Windows PowerShell blogs
  • A free ebook, Mastering PowerShell, written by Microsoft MVP Dr. Tobias Weltner
PowerTip of the Day

Unzipping ZIP Files with PowerShell 3.0 and 4.0

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!

Copyright 2012 PowerShell.com. All rights reserved.