Code/Expand-ZipFile.ps1

#requires -version 2.0
###############################################################################
# WintellectPowerShell Module
# Copyright (c) 2010-2014 - John Robbins/Wintellect
#
# Do whatever you want with this module, but please do give credit.
###############################################################################

# Always make sure all variables are defined and all best practices are
# followed.
Set-StrictMode -version Latest

###############################################################################
# Public Cmdlets
###############################################################################
function Expand-ZipFile
{
<#
.SYNOPSIS
Expands a .ZIP file to the specified directory.
 
.DESCRIPTION
Using no external ZIP utilities, expands a .ZIP file to a specified directory.
 
.PARAMETER ZipFile
The .ZIP file to expand.
 
.PARAMETER Destination
The output directory for the ZipFile. If this directory does not exist, it will
be created.
 
.LINK
http://www.wintellect.com/blogs/jrobbins
https://github.com/Wintellect/WintellectPowerShell
 
#>


    param ( 
        [Parameter(Mandatory=$true,
                   HelpMessage="Please specify the zip file to expand")]
        [string] $ZipFile ,
        [Parameter(Mandatory=$true,
                   HelpMessage="Please specify the directory to expand into")]
        [string] $Destination
    ) 
    # Basic idea found here
    # http://ochoco.blogspot.com/2009/04/quick-bytes-unzipping-zip-file-using.html.
    # Tweaked to be more usable.
    
    if (! (Test-Path -Path  $ZipFile))
    {
        throw "The zip file must exist."
    }
    
    New-Item  -Path $Destination -ItemType Directory -ErrorAction SilentlyContinue > $null
    
    # It's important you get the full path for everything or the shell application
    # doesn't like you.
    $Destination = Resolve-Path -Path $Destination 
    $ZipFile = Resolve-Path -Path $ZipFile
    
    $shellApplication = New-Object -ComObject shell.application 
    $zipPackage = $shellApplication.NameSpace($ZipFile) 
    $destinationFolder = $shellApplication.NameSpace($Destination) 
    # The first parameter to CopyHere are all the files, the second parameter
    # of 20 says to turn off the default UI of the progress dialog and say
    # yes to all dialog boxes.
    # All the codes can be found here:
    # http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/b77840b8-459d-4509-8cc8-8fc7f6603e86
    $destinationFolder.CopyHere($zipPackage.Items(),20) 
}

# SIG # Begin signature block
# MIIYSwYJKoZIhvcNAQcCoIIYPDCCGDgCAQExCzAJBgUrD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