# encoding: ascii
# api: powershell
# title: Expand-ZipFile
# description: Extracts the contents of a ZIP file to a folder
# version: 0.1
# type: function
# author: Thomas Freudenbe
# license: CC0
# function: Expand-ZipFile
# x-poshcode-id: 5905
# x-archived: 2015-06-26T07:16:50
# x-published: 2015-06-24T13:40:00
#
#
function Expand-ZipFile {
    param {
       $zipPath,
       $destination,
       [switch] $quiet
    }

    $shellApplication = new-object -com shell.application
    $zipPackage = $shellApplication.NameSpace($zipPath)
    $destinationFolder = $shellApplication.NameSpace($destination) 

    # CopyHere vOptions Flag # 4 - Do not display a progress dialog box. 
    # 16 - Respond with "Yes to All" for any dialog box that is displayed. 
    #$destinationFolder.CopyHere($zipPackage.Items(),20) 
    $total = $zipPackage.Items().Count
    $progress = 1;
    foreach ($zipFile in $zipPackage.Items()) {
        if(!$quiet) {
            Write-Progress "Extracting $zipPath" "Extracting $($zipFile.Name)" -id 0 -percentComplete (($progress/$total)*100)        
        }

        $destinationFolder.CopyHere($zipFile,20) 
        $progress++
    }
    if(!$quiet) {
        Write-Progress "Extracted $zipPath" "Extracted $total items" -id 0
    }
}
